Skip to content

Compiler crash in SymDenotations.scala related to opaque types #13761

@mpilquist

Description

@mpilquist

Compiler version

3.1.0-RC2 and 3.0.2

Minimized code

I have not yet successfully minimized, but it likely involves a pattern like this:

trait Parsers[Parser[+_]]:
  extension [A](p: Parser[A])
    def run(s: String): A
  def succeed[A](a: A): Parser[A]
object Reference extends Parsers[Reference.Parser]:
  opaque type Parser[+A] = String => A
  extension [A](p: Parser[A])
    def run(s: String): A = p(s)
  def succeed[A](a: A): Parser[A] = _ => a
def usage[Parser[+_]](P: Parsers[Parser]) =
  import P.*
  succeed(0).run("")
usage(Reference)

To reproduce:

  1. git clone https://github.com/fpinscala/fpinscala
  2. git checkout 96a31e98ec40cd70718f2948224c993561266c65
  3. sbt ";project answers; console"
  4. Enter the following code:
scala> import fpinscala.parsing.*
scala> JSON.jsonParser(Reference)

Changing opaque type Parser[+A] = Location => Result[A] to type Parser[+A] = Location => Result[A] avoids the issue.

Output (click arrow to expand)

  sbt ";project answers;console"
[info] welcome to sbt 1.5.5 (AdoptOpenJDK Java 11.0.9)
[info] loading settings for project fpinscala-build-build-build from metals.sbt ...
[info] loading project definition from /Users/mpilquist/Development/oss/fpinscala/project/project/project
[info] loading settings for project fpinscala-build-build from metals.sbt ...
[info] loading project definition from /Users/mpilquist/Development/oss/fpinscala/project/project
[success] Generated .bloop/fpinscala-build-build.json
[success] Total time: 1 s, completed Oct 17, 2021, 7:52:30 PM
[info] loading settings for project fpinscala-build from metals.sbt,plugins.sbt ...
[info] loading project definition from /Users/mpilquist/Development/oss/fpinscala/project
[success] Generated .bloop/fpinscala-build.json
[success] Total time: 0 s, completed Oct 17, 2021, 7:52:31 PM
[info] loading settings for project fpinscala from build.sbt ...
[info] set current project to fpinscala (in build file:/Users/mpilquist/Development/oss/fpinscala/)
[info] set current project to answers (in build file:/Users/mpilquist/Development/oss/fpinscala/)
Welcome to Scala 3.1.0-RC2 (11.0.9, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> import fpinscala.parsing.*

scala> JSON.jsonParser(Reference)
[error] (run-main-0) scala.MatchError: TermRef(ThisType(TypeRef(NoPrefix,module class parsing)),Reference) (of class dotty.tools.dotc.core.Types$CachedTermRef)
[error] scala.MatchError: TermRef(ThisType(TypeRef(NoPrefix,module class parsing)),Reference) (of class dotty.tools.dotc.core.Types$CachedTermRef)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.recur$4(SymDenotations.scala:421)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.setAlias$1(SymDenotations.scala:422)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.opaqueToBounds(SymDenotations.scala:436)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler.dotty$tools$dotc$core$tasty$TreeUnpickler$TreeReader$$_$_$opaqueToBounds$1(TreeUnpickler.scala:872)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readNewDef(TreeUnpickler.scala:876)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedDef(TreeUnpickler.scala:776)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$Completer.complete(TreeUnpickler.scala:122)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
[error] 	at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1118)
[error] 	at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1076)
[error] 	at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:135)
[error] 	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2067)
[error] 	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:683)
[error] 	at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:870)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler.dotty$tools$dotc$core$tasty$TreeUnpickler$TreeReader$$_$accessibleDenot$1(TreeUnpickler.scala:1093)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.completeSelect$1(TreeUnpickler.scala:1084)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readSimpleTerm$1(TreeUnpickler.scala:1112)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTerm(TreeUnpickler.scala:1299)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1329)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.$anonfun$27(TreeUnpickler.scala:1265)
[error] 	at dotty.tools.tasty.TastyReader.until(TastyReader.scala:125)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTerm$1(TreeUnpickler.scala:1265)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTerm(TreeUnpickler.scala:1299)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1329)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.$anonfun$4(TreeUnpickler.scala:937)
[error] 	at dotty.tools.tasty.TastyReader.collectWhile(TastyReader.scala:137)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTemplate(TreeUnpickler.scala:939)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readNewDef(TreeUnpickler.scala:857)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedDef(TreeUnpickler.scala:776)
[error] 	at dotty.tools.dotc.core.tasty.TreeUnpickler$Completer.complete(TreeUnpickler.scala:122)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
[error] 	at dotty.tools.dotc.core.Types$NamedType.info(Types.scala:2179)
[error] 	at dotty.tools.dotc.core.Types$Type.isRef(Types.scala:192)
[error] 	at dotty.tools.dotc.core.TypeComparer.isBottom(TypeComparer.scala:115)
[error] 	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:394)
[error] 	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:384)
[error] 	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1315)
[error] 	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:195)
[error] 	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:205)
[error] 	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:128)
[error] 	at dotty.tools.dotc.core.TypeComparer.testSubType(TypeComparer.scala:154)
[error] 	at dotty.tools.dotc.core.TypeComparer$.testSubType(TypeComparer.scala:2741)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$4(Typer.scala:3585)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3682)
[error] 	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3873)
[error] 	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3224)
[error] 	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:433)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853)
[error] 	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:544)
[error] 	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:609)
[error] 	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:447)
[error] 	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:735)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:852)
[error] 	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1060)
[error] 	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317)
[error] 	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:107)
[error] 	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:907)
[error] 	at dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:986)
[error] 	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3011)
[error] 	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:997)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1035)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317)
[error] 	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:107)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2755)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3003)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1429)
[error] 	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1419)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1429)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1681)
[error] 	at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:225)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadRhs$2(Namer.scala:1681)
[error] 	at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1689)
[error] 	at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1716)
[error] 	at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1717)
[error] 	at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1728)
[error] 	at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1468)
[error] 	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1475)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:751)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:887)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:779)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:369)
[error] 	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2697)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2722)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] 	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2409)
[error] 	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2743)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2747)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] 	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2532)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2788)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3003)
[error] 	at dotty.tools.dotc.typer.TyperPhase.liftedTree1$1(TyperPhase.scala:56)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:62)
[error] 	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:63)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$1(TyperPhase.scala:105)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.immutable.List.foreach(List.scala:333)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:105)
[error] 	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:261)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] 	at dotty.tools.dotc.Run.runPhases$5(Run.scala:272)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] 	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:289)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:228)
[error] 	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:155)
[error] 	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:165)
[error] 	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:250)
[error] 	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:218)
[error] 	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:152)
[error] 	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:155)
[error] 	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:174)
[error] 	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:155)
[error] 	at xsbt.ConsoleInterface.run(ConsoleInterface.java:52)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error] 	at sbt.internal.inc.AnalyzingCompiler.invoke(AnalyzingCompiler.scala:329)
[error] 	at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:233)
[error] 	at sbt.Console.console0$1(Console.scala:64)
[error] 	at sbt.Console.$anonfun$apply$5(Console.scala:74)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] 	at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17)
[error] 	at sbt.TrapExit$App.run(TrapExit.scala:258)
[error] 	at java.base/java.lang.Thread.run(Thread.java:834)
[error] Nonzero exit code: 1
[error] (Compile / console) Nonzero exit code: 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions