Skip to content

Scala doc crashes with AssertionError on macro generated code #22265

Closed
@Jentsch

Description

@Jentsch
Contributor

Compiler version

Breaks since 3.4.0 up to 3.6.4-RC1-bin-20241120-bd07317-NIGHTLY with java.lang.AssertionError: assertion failed. 3.3.0 breaks for another reason, which I didn't investigated further.

Minimized code

Command to reproduce: scala-cli doc *.scala -o scala-doc --server=false in a folder with the two scala files below.

TestBuilder.scala:

import scala.quoted._

object TestBuilder:
  // transparent is needed
  transparent inline def apply(inline expr: Unit): Any =
    ${ TestBuilder.processTests('expr) }

  def processTests(using Quotes)(body: Expr[Unit]): Expr[Any] =
    import quotes.reflect._
    body.asTerm match {
      case Inlined(_, _, bindings) =>
        '{ ${bindings.asExpr}; () } // can also be List(${bindings})
    }

breaks.scala:

object breaks {
  TestBuilder:
    import List.empty
}

Output (click arrow to expand)

Warning: setting /workspaces/scala-ideas/tests as the project root directory for this run.

exception occurred while readTasty class file breaks

An unhandled exception was thrown in the compiler.
Please file a crash report here:
https://github.com/scala/scala3/issues/new/choose
For non-enriched exceptions, compile with -Xno-enrich-error-messages.

 while compiling: class file breaks
    during phase: readTasty
            mode: Mode(ImplicitsEnabled,ReadPositions)
 library version: version 2.13.14
compiler version: version 3.5.2
        settings: -Xread-docs true -Yretain-trees true -classpath /workspaces/scala-ideas/tests/.scala-build/tests_ef31ba4fc4-4bd17f3955/classes/main/:/workspaces/scala-ideas/tests/.scala-build/tests_ef31ba4fc4-4bd17f3955/classes/main:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.5.2/scala3-library_3-3.5.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scaladoc_3/3.5.2/scaladoc_3-3.5.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.5.2/scala3-compiler_3-3.5.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-tasty-inspector_3/3.5.2/scala3-tasty-inspector_3-3.5.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark/0.62.2/flexmark-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-ast/0.62.2/flexmark-util-ast-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-data/0.62.2/flexmark-util-data-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-html/0.62.2/flexmark-util-html-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-anchorlink/0.62.2/flexmark-ext-anchorlink-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-autolink/0.62.2/flexmark-ext-autolink-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-emoji/0.62.2/flexmark-ext-emoji-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-gfm-strikethrough/0.62.2/flexmark-ext-gfm-strikethrough-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-gfm-tasklist/0.62.2/flexmark-ext-gfm-tasklist-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-wikilink/0.62.2/flexmark-ext-wikilink-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-tables/0.62.2/flexmark-ext-tables-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-yaml-front-matter/0.62.2/flexmark-ext-yaml-front-matter-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/nl/big-o/liqp/0.8.2/liqp-0.8.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jsoup/jsoup/1.17.2/jsoup-1.17.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.15.1/jackson-dataformat-yaml-2.15.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-interfaces/3.5.2/scala3-interfaces-3.5.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.5.2/scala3-library_3-3.5.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/tasty-core_3/3.5.2/tasty-core_3-3.5.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-asm/9.7.0-scala-2/scala-asm-9.7.0-scala-2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/compiler-interface/1.9.6/compiler-interface-1.9.6.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-reader/3.25.1/jline-reader-3.25.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal/3.25.1/jline-terminal-3.25.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal-jna/3.25.1/jline-terminal-jna-3.25.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-builder/0.62.2/flexmark-util-builder-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-collection/0.62.2/flexmark-util-collection-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-dependency/0.62.2/flexmark-util-dependency-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-format/0.62.2/flexmark-util-format-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-misc/0.62.2/flexmark-util-misc-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-sequence/0.62.2/flexmark-util-sequence-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-visitor/0.62.2/flexmark-util-visitor-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/annotations/15.0/annotations-15.0.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util/0.62.2/flexmark-util-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/nibor/autolink/autolink/0.6.0/autolink-0.6.0.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-jira-converter/0.62.2/flexmark-jira-converter-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.15.1/jackson-annotations-2.15.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.15.1/jackson-core-2.15.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.15.1/jackson-databind-2.15.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.1/jackson-datatype-jsr310-2.12.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/ua/co/k/strftime4j/1.0.5/strftime4j-1.0.5.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/yaml/snakeyaml/2.0/snakeyaml-2.0.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/util-interface/1.9.8/util-interface-1.9.8.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-native/3.25.1/jline-native-3.25.1.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-options/0.62.2/flexmark-util-options-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-ins/0.62.2/flexmark-ext-ins-0.62.2.jar:/home/vscode/.cache/coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-superscript/0.62.2/flexmark-ext-superscript-0.62.2.jar -from-tasty true

Exception in thread "main" java.lang.AssertionError: assertion failed
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStat(TreeUnpickler.scala:1172)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStats(TreeUnpickler.scala:1222)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readStats(TreeUnpickler.scala:1232)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1421)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1431)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStat(TreeUnpickler.scala:1181)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStats(TreeUnpickler.scala:1222)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readStats(TreeUnpickler.scala:1232)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1421)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1431)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1253)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1431)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStat(TreeUnpickler.scala:1181)
at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStats(TreeUnpickler.scala:1222)
at dotty.tools.dotc.core.tasty.TreeUnpickler.$anonfun$24$$anonfun$1(TreeUnpickler.scala:1136)
at dotty.tools.dotc.core.tasty.TreeUnpickler$LazyReader.complete(TreeUnpickler.scala:1738)
at dotty.tools.dotc.ast.Trees$WithLazyFields.force(Trees.scala:1125)
at dotty.tools.dotc.ast.Trees$WithLazyFields.force$(Trees.scala:1121)
at dotty.tools.dotc.ast.Trees$Template.force(Trees.scala:969)
at dotty.tools.dotc.ast.Trees$Template.forceFields(Trees.scala:975)
at dotty.tools.dotc.ast.Trees$Template.parentsOrDerived(Trees.scala:979)
at dotty.tools.dotc.ast.Trees$Template.parents(Trees.scala:981)
at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1757)
at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1799)
at dotty.tools.dotc.CompilationUnit$Force.traverse(CompilationUnit.scala:202)
at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1798)
at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1798)
at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1754)
at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1799)
at dotty.tools.dotc.CompilationUnit$Force.traverse(CompilationUnit.scala:202)
at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1798)
at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1798)
at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1662)
at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1664)
at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1763)
at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1668)
at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1799)
at dotty.tools.dotc.CompilationUnit$Force.traverse(CompilationUnit.scala:202)
at dotty.tools.dotc.CompilationUnit$.apply(CompilationUnit.scala:150)
at dotty.tools.dotc.CompilationUnit$.apply(CompilationUnit.scala:141)
at dotty.tools.dotc.fromtasty.ReadTasty.compilationUnit$1(ReadTasty.scala:57)
at dotty.tools.dotc.fromtasty.ReadTasty.readTASTY(ReadTasty.scala:85)
at dotty.tools.dotc.fromtasty.ReadTasty.addTasty$$anonfun$1(ReadTasty.scala:33)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:503)
at dotty.tools.dotc.fromtasty.ReadTasty.addTasty(ReadTasty.scala:33)
at dotty.tools.dotc.fromtasty.ReadTasty.runOn$$anonfun$1(ReadTasty.scala:28)
at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:619)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:617)
at scala.collection.AbstractIterable.foreach(Iterable.scala:935)
at scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:905)
at dotty.tools.dotc.fromtasty.ReadTasty.runOn(ReadTasty.scala:28)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
at dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
at dotty.tools.dotc.Run.compileUnits(Run.scala:396)
at dotty.tools.dotc.Run.compileUnits(Run.scala:288)
at dotty.tools.dotc.fromtasty.TASTYRun.compile(TASTYRun.scala:15)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
at dotty.tools.dotc.Driver.process(Driver.scala:201)
at dotty.tools.dotc.Driver.process(Driver.scala:169)
at dotty.tools.dotc.Driver.process(Driver.scala:181)
at scala.tasty.inspector.TastyInspector$.inspectFiles(TastyInspector.scala:121)
at scala.tasty.inspector.TastyInspector$.inspectAllTastyFiles(TastyInspector.scala:62)
at dotty.tools.scaladoc.tasty.ScaladocTastyInspector$.loadDocs(TastyParser.scala:163)
at dotty.tools.scaladoc.ScalaModuleProvider$.mkModule(ScalaModuleProvider.scala:11)
at dotty.tools.scaladoc.Scaladoc$.run(Scaladoc.scala:240)
at dotty.tools.scaladoc.Scaladoc$.run$$anonfun$1(Scaladoc.scala:70)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.Option.map(Option.scala:242)
at dotty.tools.scaladoc.Scaladoc$.run(Scaladoc.scala:55)
at dotty.tools.scaladoc.Main.run(Main.scala:8)
at dotty.tools.scaladoc.Main$.main(Main.scala:14)
at dotty.tools.scaladoc.Main.main(Main.scala)
[error] Scaladoc generation failed (exit code: 1)

The original codes comes from utest

Activity

Jentsch

Jentsch commented on Dec 27, 2024

@Jentsch
ContributorAuthor

The vilolated assertion seems to be assert(sourcePathAt(start).isEmpty) here:

    inline def readImportOrExport(inline mkTree:
        (Tree, List[untpd.ImportSelector]) => Tree)()(using Context): Tree = {
      val start = currentAddr
      assert(sourcePathAt(start).isEmpty)
      readByte()
      readEnd()
      val expr = readTree()
      setSpan(start, mkTree(expr, readSelectors()))
    }

Removing that assert produces correct looking documentation, but the assert is probably there for a reason...

added
area:tasty-formatissues relating to TASTy as a portable standard
regressionThis worked in a previous version but doesn't anymore
and removed
stat:needs triageEvery issue needs to have an "area" and "itype" label
regressionThis worked in a previous version but doesn't anymore
on Dec 30, 2024
Gedochao

Gedochao commented on Dec 30, 2024

@Gedochao
Contributor

BTW it also breaks for 3.3.1-3.3.4 (and 3.3.5-RC1, too).
So even if it's a different error in 3.3, it's not a regression.
cc @Florian3k

added a commit that references this issue on Jun 11, 2025
5ca5a3e
added a commit that references this issue on Jul 3, 2025
c0f8d70
added a commit that references this issue on Jul 8, 2025
b699e98
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

    No milestone

    Relationships

    None yet

      Participants

      @Jentsch@Gedochao@Florian3k

      Issue actions

        Scala doc crashes with AssertionError on macro generated code · Issue #22265 · scala/scala3