Skip to content

AssertionError "start of NoSpan" in Typer.adaptToArgs from PR #25699's multiline-context detection #26015

Closed

Description

@soronpo

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.srcPos

Span.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)

  1. Inside an inline expansion (Inlines.inlineCall → Inlines.Intrinsics.typeCheckErrors → packErrors → packError):
  2. A TypeMismatch error is reported.
  3. Building the diagnostic message goes through Diagnostic.message → Message.message → TypeMismatch.msgPostscript → importSuggestionAddendum.
  4. ImportSuggestions.importSuggestions partitions candidates by deepTest.
  5. deepTest calls typedImplicit with a synthetic Ident(ref.name).withSpan(ctx.owner.srcPos.span) — and ctx.owner.srcPos.span is NoSpan when the owner is synthetic (which it can be inside the inline expansion's reTyper context).
  6. Implicits.tryConversion builds untpd.Apply(untpdConv, untpd.TypedSplice(argument) :: Nil) and types it.
  7. If untpdConv is not a function (i.e. the candidate doesn't yield a Conversion), adaptToArgs falls through to the tryInsertApplyOrImplicit branch with pt.args.last.srcPos.span = NoSpan and tree.srcPos.span = NoSpan.
  8. tree.srcPos.span.union(pt.args.last.srcPos.span) → NoSpan; union.startLine crashes.

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

  1. som-snytt commented on May 8, 2026

    @som-snytt
    Contributor

    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...

  2. soronpo commented on May 8, 2026

    @soronpo
    ContributorAuthor

    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...

    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 :)

  3. soronpo commented on May 9, 2026

    @soronpo
    ContributorAuthor

    See PR for minimized reproducer.

  4. added a commit that references this issue on May 23, 2026
    0d03148
  5. added this to the 3.9.0 milestone on May 26, 2026
  6. added a commit that references this issue on Jun 5, 2026
    5421a2a
  7. added a commit that references this issue on Aug 6, 2026
    0d0d8f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions