Skip to content

java.lang.Error when compiling code using a value and a pdt defined as a wildcard type argument #15311

Closed
@noresttherein

Description

@noresttherein

Scala 3.1.2

trait Template[+T <: Template[T]]:
   type Clone <: T { type Clone = Template.this.Clone }
   val self :Clone

type Food = Template[_]

class Ham extends Template[Ham]:
   type Clone = Ham
   val self = this

def eat[F <: Template[F]](food :F) :F = food.self.self

val ham = new Ham
val food :Food = ham

eat(ham)
eat(food.self)

Output

java.lang.Error: internal error: type of right-hand side Playground.Template[Playground.food.T] is not fully defined, pos = [929..933..952]
	at dotty.tools.dotc.typer.Inferencing$.fullyDefinedType(Inferencing.scala:57)
	at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1717)
	at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1728)
	at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1468)
	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1475)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:751)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:887)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:779)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:369)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2697)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2722)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1027)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1031)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2763)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$5(ProtoTypes.scala:431)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:359)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:432)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:853)
	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:544)
	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:609)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:447)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:735)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:852)
	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1060)
	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:107)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:907)
	at dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:986)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3011)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:997)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1035)
	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:107)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2755)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2936)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2409)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2743)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2747)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2532)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2788)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3003)
	at dotty.tools.dotc.typer.TyperPhase.liftedTree1$1(TyperPhase.scala:56)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:62)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:63)
	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$1(TyperPhase.scala:105)
	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:105)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:261)
	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$5(Run.scala:272)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:289)
	at dotty.tools.dotc.Run.compileSources(Run.scala:222)
	at dotty.tools.dotc.Run.compile(Run.scala:206)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
	at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
	at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:192)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
	at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175)
	at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461)
	at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
	at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:416)
	at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503)
	at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403)
	at sbt.internal.inc.Incremental$.apply(Incremental.scala:169)
	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2366)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2316)
	at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30)
	at sbt.internal.io.Retry$.apply(Retry.scala:46)
	at sbt.internal.io.Retry$.apply(Retry.scala:28)
	at sbt.internal.io.Retry$.apply(Retry.scala:23)
	at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2314)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
	at sbt.std.Transform$$anon$4.work(Transform.scala:68)
	at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
	at sbt.Execute.work(Execute.scala:291)
	at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:831)

The problem is the last line.

Expectation

Should compile? Hopefully

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions