Repository navigation
Description
Compiler version
3.9.0-RC1-bin-20260501-0c8c581-NIGHTLY.
Background
PR scala/scala3#25699 ("Include span of bad args if multiline", merged 2026-04-10) added a multi-line-detection block at Typer.scala:4515-4521:
val pos =
if pt.args.isEmpty then tree.srcPos
else
val union = tree.sourcePos.withSpan:
tree.srcPos.span.union(pt.args.last.srcPos.span)
if union.startLine != union.endLine then union // if multiline, show more context
else tree.srcPosSpan.union returns NoSpan if both input spans are NoSpan (it short-circuits if either is NoSpan, returning the other). Calling .startLine on a SourcePosition wrapping a NoSpan span hits the assert(exists, "start of NoSpan") in Spans.scala:45, crashing the compiler.
Trigger path (from the jsoniter-scala stack trace)
- Inside an inline expansion (
Inlines.inlineCall→Inlines.Intrinsics.typeCheckErrors→packErrors→packError): - A
TypeMismatcherror is reported. - Building the diagnostic message goes through
Diagnostic.message→Message.message→TypeMismatch.msgPostscript→importSuggestionAddendum. ImportSuggestions.importSuggestionspartitions candidates bydeepTest.deepTestcallstypedImplicitwith a syntheticIdent(ref.name).withSpan(ctx.owner.srcPos.span)— andctx.owner.srcPos.spanis NoSpan when the owner is synthetic (which it can be inside the inline expansion's reTyper context).Implicits.tryConversionbuildsuntpd.Apply(untpdConv, untpd.TypedSplice(argument) :: Nil)and types it.- If
untpdConvis not a function (i.e. the candidate doesn't yield aConversion),adaptToArgsfalls through to thetryInsertApplyOrImplicitbranch withpt.args.last.srcPos.span = NoSpanandtree.srcPos.span = NoSpan. tree.srcPos.span.union(pt.args.last.srcPos.span)→ NoSpan;union.startLinecrashes.
Stack trace (from community-build3, jsoniter-scala 2.38.9)
java.lang.AssertionError: assertion failed: start of NoSpan
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:10)
at dotty.tools.dotc.util.Spans$Span$.start$extension(Spans.scala:45)
at dotty.tools.dotc.util.SourcePosition.start(SourcePosition.scala:55)
at dotty.tools.dotc.util.SourcePosition.startLine(SourcePosition.scala:56)
at dotty.tools.dotc.typer.Typer.adaptToArgs$1$$anonfun$1(Typer.scala:4507)
at dotty.tools.dotc.typer.ReTyper.tryInsertApplyOrImplicit(ReTyper.scala:155)
at dotty.tools.dotc.typer.Typer.adaptToArgs$1(Typer.scala:4509)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:5202)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:4400)
... // through implicit-conversion testing
at dotty.tools.dotc.typer.Implicits.tryConversion$1(Implicits.scala:1216)
at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1247)
at dotty.tools.dotc.typer.ImportSuggestions.deepTest$1(ImportSuggestions.scala:216)
at dotty.tools.dotc.typer.ImportSuggestions.importSuggestions$$anonfun$2(ImportSuggestions.scala:253)
at dotty.tools.dotc.typer.ImportSuggestions.importSuggestions(ImportSuggestions.scala:253)
at dotty.tools.dotc.typer.ImportSuggestions.importSuggestionAddendum(ImportSuggestions.scala:328)
at dotty.tools.dotc.reporting.TypeMismatch.importSuggestions$1(messages.scala:369)
at dotty.tools.dotc.reporting.TypeMismatch.msgPostscript(messages.scala:370)
at dotty.tools.dotc.reporting.Message.message$$anonfun$1(Message.scala:442)
at dotty.tools.dotc.reporting.Message.message(Message.scala:442)
at dotty.tools.dotc.reporting.Diagnostic.message(Diagnostic.scala:126)
at dotty.tools.dotc.inlines.Inlines$Intrinsics$.dotty$tools$dotc$inlines$Inlines$Intrinsics$$$packError(Inlines.scala:469)
Proposed patch
compiler/src/dotty/tools/dotc/typer/Typer.scala, around line 4515-4523:
tryInsertApplyOrImplicit(tree, pt, locked):
val pos =
if pt.args.isEmpty then tree.srcPos
else
val unionSpan = tree.srcPos.span.union(pt.args.last.srcPos.span)
if unionSpan.exists then
val union = tree.sourcePos.withSpan(unionSpan)
if union.startLine != union.endLine then union // if multiline, show more context
else tree.srcPos
else tree.srcPos
errorTree(tree, MethodDoesNotTakeParameters(tree), pos)The guard unionSpan.exists falls back to tree.srcPos when both input spans are NoSpan. The existing i9434.check multiline-context behaviour is preserved (the rewrite is just structural — when at least one input span exists, the union exists, and the multiline check runs as before).
Reproducible example
The fully reduced trigger requires the ImportSuggestions.deepTest path to be entered with synthetic NoSpan arguments, which is hard to drive from user code without an actual macro-heavy library. The jsoniter-scala 2.38.9 macro test build deterministically triggers it; community-build3 job:
https://github.com/VirtusLab/community-build3/actions/runs/25237415541/job/74008857099
Triaged from VirtusLab community-build3 nightly run 0c8c581 (2026-05-01).
Community-build context
Hits plokhotnyuk/jsoniter-scala @ 2.38.9 in the jsoniter-scala-macros test compilation under -Xcheck-macros and the make-macro test suite. The crash is the only issue blocking the project under the current nightly.
Activity
Rename pekko-with-rewrite repro to i26015 (upstream issue number)
Add i26015 repro: `with`→`&` typed-pattern rewrite produces unparseab…
Add i26015 repro: `with`→`&` typed-pattern rewrite produces unparseab…
Fix scala#26015: accept `&` in typed-pattern type ascriptions
som-snytt commentedon May 8, 2026
The patch LGTM. Recently, I thought it would be nice for span operations to have useful defaults, but there isn't one here.
I'll submit a PR unless Claude has beaten me to it. I can try to concoct a minimized test...
soronpo commentedon May 8, 2026
It's already on the task. I had it first explore a parser fix, but I decided I don't want to go through another SIP now :)
soronpo commentedon May 9, 2026
See PR for minimized reproducer.
[OpenCB Project Fix] Fixes scala#26015: Start of NoSpan in adaptToArg…
[OpenCB Project Fix] Fixes scala#26015: Start of NoSpan in adaptToArg…
Merge pull request #1039 from scala/backport-lts-3.3-26017