Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala.MatchError dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:798) #19202

Closed
akshaal opened this issue Dec 5, 2023 · 8 comments · Fixed by #19463
Closed

scala.MatchError dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:798) #19202

akshaal opened this issue Dec 5, 2023 · 8 comments · Fixed by #19463
Labels
Milestone

Comments

@akshaal
Copy link

akshaal commented Dec 5, 2023

Compiling a minimized example with scala 3.3.1:

class Test {
    def test(s: String): Unit = {
        if (s == null) {
            return
        }

        case class XXX()
    }
}

results in

scala.MatchError: TypeDef(XXX,Template(DefDef(<init>,List(List()),TypeTree,EmptyTree),List(Select(Select(Ident(_root_),scala),Product), Select(Select(Ident(_root_),scala),Serializable)),ValDef(_,EmptyTree,EmptyTree),List(DefDef(copy,List(List()),TypeTree,Apply(Select(New(TypeTree),<init>),List()))))) (of class dotty.tools.dotc.ast.Trees$TypeDef) while typechecking /tmp/a/test.scala
exception occurred while typechecking /tmp/a/test.scala

  exception occurred while compiling List(/tmp/a/test.scala)

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/lampepfl/dotty/issues/new/choose

     while compiling: <no file>
        during phase: <no phase>
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.10
    compiler version: version 3.3.1
            settings: -classpath /home/user/opt/scala3/lib/scala-library-2.13.10.jar:/home/user/opt/scala3/lib/scala3-library_3-3.3.1.jar:/home/user/opt/scala3/lib/scala-asm-9.5.0-scala-1.jar:/home/user/opt/scala3/lib/compiler-interface-1.3.5.jar:/home/user/opt/scala3/lib/scala3-interfaces-3.3.1.jar:/home/user/opt/scala3/lib/scala3-compiler_3-3.3.1.jar:/home/user/opt/scala3/lib/tasty-core_3-3.3.1.jar:/home/user/opt/scala3/lib/scala3-staging_3-3.3.1.jar:/home/user/opt/scala3/lib/scala3-tasty-inspector_3-3.3.1.jar:/home/user/opt/scala3/lib/jline-reader-3.19.0.jar:/home/user/opt/scala3/lib/jline-terminal-3.19.0.jar:/home/user/opt/scala3/lib/jline-terminal-jna-3.19.0.jar:/home/user/opt/scala3/lib/jna-5.3.1.jar -d /tmp/scala3-scripting16613904917771917003

                tree: EmptyTree
       tree position: :<unknown>
           tree type: <notype>
              symbol: val <none>
           call site: package <root> in module class <root>

  == Source file context for tree position ==


Exception in thread "main" scala.MatchError: TypeDef(XXX,Template(DefDef(<init>,List(List()),TypeTree,EmptyTree),List(Select(Select(Ident(_root_),scala),Product), Select(Select(Ident(_root_),scala),Serializable)),ValDef(_,EmptyTree,EmptyTree),List(DefDef(copy,List(List()),TypeTree,Apply(Select(New(TypeTree),<init>),List()))))) (of class dotty.tools.dotc.ast.Trees$TypeDef)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:798)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:934)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:814)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2989)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3014)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1159)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1163)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3056)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
	at dotty.tools.dotc.typer.Typer.$anonfun$57(Typer.scala:2486)
	at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:243)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2486)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3024)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2669)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3036)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3040)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3081)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
	at scala.Function0.apply$mcV$sp(Function0.scala:42)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
	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:1321)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
	at dotty.tools.dotc.Run.compileSources(Run.scala:194)
	at dotty.tools.dotc.Run.compile(Run.scala:179)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
	at dotty.tools.scripting.ScriptingDriver.compileAndRun(ScriptingDriver.scala:22)
	at dotty.tools.scripting.Main$.process(Main.scala:45)
	at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:250)
	at dotty.tools.MainGenericRunner$.process(MainGenericRunner.scala:270)
	at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:281)
	at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)
@akshaal akshaal added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 5, 2023
@mbovel mbovel added area:typer itype:crash Spree Suitable for a future Spree and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 11, 2023
@mbovel
Copy link
Member

mbovel commented Jan 14, 2024

Still crashes as of 3.4.0-RC1-bin-20240112-c50f2ff-NIGHTLY-git-c50f2ff.

@scala-center-bot
Copy link

scala-center-bot commented Jan 14, 2024

This issue was picked for the Issue Spree No. 41 of January 16th, 2024 which takes place in 2 days. @smarter, @jan-pieter, @nmcb will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@jan-pieter
Copy link
Contributor

Some observations:

  • Still crashes on the current main branch
  • Compilation succeeds when removing the if ... return block
  • Compilation succeeds when removing the case class definition
  • Compilation succeeds when wrapping the case class definition in a block with curly braces

@mbovel
Copy link
Member

mbovel commented Jan 16, 2024

It does also work if the case class is replaced by a def:

class Test {
    def test(s: String): Unit = {
        if (s == null) {
            return
        }

        def g() = ()
    }
}

@mbovel
Copy link
Member

mbovel commented Jan 16, 2024

Compilation succeeds when wrapping the case class definition in a block with curly braces

Interesting. The difference there is that the case class and the result gets wrapped in a block:

sbt:scala3> scalac -Xprint:parser tests/pos/i19202.scala
[[syntax trees at end of                    parser]] // tests/pos/i19202.scala
package <empty> {
  class Test {
    def test(s: String): Unit =
      {
        if (s == null)
          {
            return
          }
        {
          case class XXX() {}
          <empty>
        }
      }
  }
}

Without curly braces:

sbt:scala3> scalac -Xprint:parser tests/pos/i19202.scala
[[syntax trees at end of                    parser]] // tests/pos/i19202.scala
package <empty> {
  class Test {
    def test(s: String): Unit =
      {
        if (s == null)
          {
            return
          }
        case class XXX() {}
        <empty>
      }
  }
}
...

@mbovel
Copy link
Member

mbovel commented Jan 16, 2024

The exception is a MatchError thrown from typeSig when original is a TypeDef for which there is node case:

https://github.com/lampepfl/dotty/blob/2945fd178dfc7331e476d61d79d6bb44174263aa/compiler/src/dotty/tools/dotc/typer/Namer.scala#L793-L806

@mbovel
Copy link
Member

mbovel commented Jan 16, 2024

@noti0na1 will join you to work on this issue.

@jan-pieter
Copy link
Contributor

Turns out the match fails on a TypeDef. And indeed, when replacing the case class definition with type A = String we get the same error.

noti0na1 added a commit that referenced this issue Jan 19, 2024
…eter (#19463)

Fix #19202 by passing latest `NotNullInfos` to a mutable field of a `Completer`.

Completing a `Def` requires the new NotNullInfos from previous
statements.
Originally, we created a new Completer with the new creation ctx in
`adaptCreationContext`.
However, we should not create a regular Completer for `TypeDef`s.

This PR fixes the issue by creating a mutable field for NotNullInfos in
Completer,
and the field is updated  in `adaptCreationContext` now.
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur added a commit that referenced this issue Jun 28, 2024
…mpleter" to LTS (#20841)

Backports #19463 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants