Skip to content

fix #25456: parser crash on polymorphic context bound - #25623

Merged
warcholjakub merged 2 commits into
scala:mainfrom
warcholjakub:fix/25456/polymorphic
Mar 30, 2026
Merged

fix #25456: parser crash on polymorphic context bound#25623
warcholjakub merged 2 commits into
scala:mainfrom
warcholjakub:fix/25456/polymorphic

Conversation

@warcholjakub

Copy link
Copy Markdown
Member

Fixes #25456

def generate[F[_] = : {ApplicativeError[?], _root_.scala.Any}] =
  _root_.scala.Predef.???
val newSpan = t.span.withPoint(t.span.end).withEnd(in.lastOffset)

Trying to access end on NoSpan (span of scalaAny) caused an assert to fail:

def end: Int = {
    assert(exists, "end of NoSpan")
    ((coords >>> StartEndBits) & StartEndMask).toInt
  }

The fix was to add a guard against NoSpan in contextBound.

How much have you relied on LLM-based tools in this contribution?

Minimally - to verify correctness of the solution.

How was the solution tested?

Added tests/neg/i25456.scala.

@som-snytt som-snytt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate it when that happens.

ContextBoundTypeTree(t, pname, ownName).withSpan(newSpan)
val res = ContextBoundTypeTree(t, pname, ownName)
if t.span.exists then
res.withSpan(t.span.withPoint(t.span.end).withEnd(in.lastOffset))

@som-snytt som-snytt Mar 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you choose, res.withSpan(Span(t.span.start, end = in.lastOffset, point = t.span.end)).

(Not sure if Scala 3 enforces invariants yet, but it was a Scala 2 issue that order matters.)

@warcholjakub
warcholjakub removed the request for review from SolalPirelli March 30, 2026 10:00
@warcholjakub
warcholjakub force-pushed the fix/25456/polymorphic branch from d8aa436 to 63857d8 Compare March 30, 2026 10:01
@warcholjakub
warcholjakub merged commit 48330eb into scala:main Mar 30, 2026
64 checks passed
@warcholjakub
warcholjakub deleted the fix/25456/polymorphic branch March 30, 2026 12:07
@WojciechMazur WojciechMazur added this to the 3.8.4 milestone Mar 31, 2026
@som-snytt

som-snytt commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Minimally - to verify correctness of the solution.

I almost said on the review that this is what LLM is not good at. (That is, verification.)

Apparently, I was distracted by the mechanics of constructing a span.

... removed the request for review from SolalPirelli

You know who would have asked about the other case.

@warcholjakub

Copy link
Copy Markdown
Member Author

Yeah, that's my bad. I thought that with a change so minimal, one review would suffice and didn't want to bother more people.

@som-snytt

Copy link
Copy Markdown
Contributor

No, totally my bad.

som-snytt added a commit that referenced this pull request Apr 16, 2026
Fixes #25716 

Follow-up #25623

Supply a span at `ContextBound` (rather than defensively checking for a
span up the stack).
tgodzik added a commit that referenced this pull request May 26, 2026
Fixes #25716 

Follow-up #25623

Supply a span at `ContextBound` (rather than defensively checking for a
span up the stack).
[Cherry-picked 0bb5237][modified]
bishabosha pushed a commit to dotty-staging/dotty that referenced this pull request Jun 5, 2026
Fixes scala#25716 

Follow-up scala#25623

Supply a span at `ContextBound` (rather than defensively checking for a
span up the stack).
alexarchambault pushed a commit to plasmon-scala/scala3 that referenced this pull request Jun 16, 2026
Fixes scala#25716 

Follow-up scala#25623

Supply a span at `ContextBound` (rather than defensively checking for a
span up the stack).
[Cherry-picked 0bb5237]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: "exception occurred while parsing" with polymorphic context bounds on higher-kinded type

4 participants