scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

Crash on cyclic reference #15431

Closed anatoliykmetyuk closed 2 years ago

anatoliykmetyuk commented 2 years ago

Compiler version

3.1.2

Minimized code

trait Foo:
  def get(x: Int): Long = ???

def dummy(pQueue: Foo) = ???
def Test = query(dummy(_))

type Gettable[Ptr, T] = Ptr { def get(x: Int): T }
def query[T, Ptr <: Gettable[Ptr, T]](function: Gettable[Ptr, T] => Int): T = ???

Output (click arrow to expand)

```scala java.lang.AssertionError: assertion failed: Function(List(ValDef(_$1,TypeTree,EmptyTree)),Apply(Ident(dummy),List(Ident(_$1)))) while compiling /Users/kmetiuk/Projects/GameDev/vulkan-tutorial/src/main/scala/Crash.scala [error] ## Exception when compiling 7 sources to /Users/kmetiuk/Projects/GameDev/vulkan-tutorial/target/scala-3.1.2/classes [error] java.lang.AssertionError: assertion failed: Function(List(ValDef(_$1,TypeTree,EmptyTree)),Apply(Ident(dummy),List(Ident(_$1)))) [error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8) [error] dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldMoreCases(Trees.scala:1629) [error] dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1624) [error] dotty.tools.dotc.ast.tpd$$anon$5.apply(tpd.scala:1090) [error] dotty.tools.dotc.ast.tpd$$anon$5.apply(tpd.scala:1090) [error] dotty.tools.dotc.ast.tpd$TreeOps$.existsSubTree$extension(tpd.scala:1092) [error] dotty.tools.dotc.typer.ProtoTypes$FunProto.hasInnerErrors(ProtoTypes.scala:369) [error] dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:388) [error] dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:463) [error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853) [error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853) [error] dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:544) [error] dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:609) [error] dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:447) [error] dotty.tools.dotc.typer.Applications$TypedApply.(Applications.scala:735) [error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.(Applications.scala:852) [error] dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1052) [error] dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317) [error] dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:119) [error] dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898) [error] dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$3(Applications.scala:978) [error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3081) [error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:989) [error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1027) [error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317) [error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:119) [error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2809) [error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941) [error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057) [error] dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1473) [error] dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1463) [error] dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1473) [error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1710) [error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:238) [error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1710) [error] dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1718) [error] dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1736) [error] dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1737) [error] dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1748) [error] dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1512) [error] dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1519) [error] dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1588) [error] dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:782) [error] dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:914) [error] dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:806) [error] dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:168) [error] dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188) [error] dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190) [error] dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:370) [error] dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2751) [error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2776) [error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941) [error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963) [error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013) [error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2454) [error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2797) [error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2801) [error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941) [error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963) [error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013) [error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2581) [error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2842) [error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937) [error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941) [error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057) [error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47) [error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411) [error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54) [error] dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.immutable.List.foreach(List.scala:333) [error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88) [error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:259) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328) [error] dotty.tools.dotc.Run.runPhases$1(Run.scala:270) [error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:278) [error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) [error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68) [error] dotty.tools.dotc.Run.compileUnits(Run.scala:287) [error] dotty.tools.dotc.Run.compileSources(Run.scala:220) [error] dotty.tools.dotc.Run.compile(Run.scala:204) [error] dotty.tools.dotc.Driver.doCompile(Driver.scala:39) [error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88) [error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22) [error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:192) [error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) [error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163) [error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) [error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163) [error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175) [error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461) [error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) [error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263) [error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:416) [error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503) [error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403) [error] sbt.internal.inc.Incremental$.apply(Incremental.scala:169) [error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482) [error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) [error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420) [error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) [error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2366) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2316) [error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30) [error] sbt.internal.io.Retry$.apply(Retry.scala:46) [error] sbt.internal.io.Retry$.apply(Retry.scala:28) [error] sbt.internal.io.Retry$.apply(Retry.scala:23) [error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2314) [error] scala.Function1.$anonfun$compose$1(Function1.scala:49) [error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62) [error] sbt.std.Transform$$anon$4.work(Transform.scala:68) [error] sbt.Execute.$anonfun$submit$2(Execute.scala:282) [error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23) [error] sbt.Execute.work(Execute.scala:291) [error] sbt.Execute.$anonfun$submit$1(Execute.scala:282) [error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) [error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64) [error] java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [error] java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [error] java.lang.Thread.run(Thread.java:748) ```

Expectation

Should probably be an error about the cyclic reference of a type parameter, not a crash.

odersky commented 2 years ago

On latest main I get:

5 |def Test = query(dummy(_))
  |                 ^
  |                 Cyclic reference involving trait Foo
  |
  | longer explanation available when compiling with `-explain`
1 error found
anatoliykmetyuk commented 2 years ago

Ok, I tried it on the latest main and can't reproduce it either. Maybe it was fixed between 3.1.2 and now.

som-snytt commented 2 years ago

I think "cannot reproduce" tag would constitute "gaslighting". Maybe you need a "fixed on HEAD" label.