scala/scala3

Referring to `Fields` from an `using` clause in `selectDynamic` crashes the compiler

Opened this issue · 0 comments

Compiler version

Scala 3.5.1-RC1-bin-20240530-01b404f-NIGHTLY

Minimized code

//> using scala 3.5.1-RC1-bin-20240530-01b404f-NIGHTLY
//> using option "-language:experimental.namedTuples"

import NamedTuple.*

trait Selector extends Selectable {
  type Fields = (int: Int, str: String)

  def selectDynamic(name: String)(using name.type <:< Tuple.Union[NamedTuple.Names[Fields]]) = ???
}

@main def main = {
  val sel2: Selector = new Selector {}
  val asd = sel2.int
}

Output (click arrow to expand)

  exception occurred while typechecking /home/aleksander/repos/no-trees-here/Main.scala

  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: /home/aleksander/repos/no-trees-here/Main.scala
        during phase: typer
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.5.1-RC1-bin-20240530-01b404f-NIGHTLY-git-01b404f
            settings: -bootclasspath /home/aleksander/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.5.1-RC1-bin-20240530-01b404f-NIGHTLY/scala3-library_3-3.5.1-RC1-bin-20240530-01b404f-NIGHTLY.jar:/home/aleksander/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -classpath /home/aleksander/repos/no-trees-here/.scala-build/.bloop/no-trees-here_89818ceafc/bloop-internal-classes/main-Ip7KqxcKTeKbofVYRgIEtg==:/home/aleksander/repos/no-trees-here/.scala-build/no-trees-here_89818ceafc/classes/classes-empty-no-trees-here_89818ceafc -d /home/aleksander/repos/no-trees-here/.scala-build/.bloop/no-trees-here_89818ceafc/bloop-internal-classes/main-Ip7KqxcKTeKbofVYRgIEtg== -java-output-version 17 -language List(experimental.namedTuples) -sourceroot /home/aleksander/repos/no-trees-here

Error compiling project (Scala 3.5.1-RC1-bin-20240530-01b404f-NIGHTLY, JVM (17))
Error: Unexpected error when compiling no-trees-here_89818ceafc: java.lang.AssertionError: assertion failed: invalid prefix ContextualMethodType(List(x$2), List(AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class <:<),List(ConstantType(Constant(int)), OrType(ConstantType(Constant(int)),OrType(ConstantType(Constant(str)),TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Nothing)))))), TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing))
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.Types$NamedType.<init>(Types.scala:2377)
        at dotty.tools.dotc.core.Types$TermRef.<init>(Types.scala:2982)
        at dotty.tools.dotc.core.Types$CachedTermRef.<init>(Types.scala:3079)
        at dotty.tools.dotc.core.Uniques$NamedTypeUniques.newType$1(Uniques.scala:44)
        at dotty.tools.dotc.core.Uniques$NamedTypeUniques.enterIfNew(Uniques.scala:46)
        at dotty.tools.dotc.core.Types$TermRef$.apply(Types.scala:3133)
        at dotty.tools.dotc.core.Types$TermRef$.apply(Types.scala:3139)
        at dotty.tools.dotc.ast.tpd$TreeOps$.select$extension(tpd.scala:916)
        at dotty.tools.dotc.ast.tpd$TreeOps$.cast$extension(tpd.scala:1014)
        at dotty.tools.dotc.ast.tpd$TreeOps$.cast$extension(tpd.scala:1009)
        at dotty.tools.dotc.ast.tpd$TreeOps$.ensureConforms$extension(tpd.scala:1023)
        at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:841)
        at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:941)
        at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:979)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3372)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3481)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3559)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3563)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3674)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1747)
        at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1737)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1747)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:2073)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:2073)
        at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:2081)
        at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:2100)
        at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:2101)
        at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:2112)
        at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1779)
        at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1785)
        at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:823)
        at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:974)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:850)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
        at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3344)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3369)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3481)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3559)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3563)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3585)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3631)
        at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1375)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1379)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3405)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3482)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3559)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3563)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3674)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1747)
        at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1737)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1747)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:2073)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:2073)
        at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:2081)
        at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:2100)
        at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:2101)
        at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:2112)
        at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1779)
        at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1785)
        at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1959)
        at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:827)
        at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:974)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:850)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
        at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3344)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3369)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3481)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3559)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3563)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3585)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3631)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3079)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3385)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3389)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3481)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3559)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3563)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3585)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3631)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3212)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3431)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3482)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3559)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3563)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3674)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
        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.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
        at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
        at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
        at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
        at scala.collection.immutable.List.prependedAll(List.scala:152)
        at scala.collection.immutable.List$.from(List.scala:684)
        at scala.collection.immutable.List$.from(List.scala:681)
        at scala.collection.IterableOps$WithFilter.map(Iterable.scala:898)
        at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
        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.compileSources(Run.scala:282)
        at dotty.tools.dotc.Run.compile(Run.scala:267)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
        at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
        at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.compileSources$1(BloopHighLevelCompiler.scala:133)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$7(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$1(BloopHighLevelCompiler.scala:71)
        at bloop.tracing.NoopTracer$.trace(BraveTracer.scala:53)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:70)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$6(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:81)
        at monix.eval.internal.TaskRestartCallback.syncOnSuccess(TaskRestartCallback.scala:101)
        at monix.eval.internal.TaskRestartCallback.onSuccess(TaskRestartCallback.scala:74)
        at monix.eval.internal.TaskExecuteOn$AsyncRegister$$anon$1.run(TaskExecuteOn.scala:71)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Compilation failed