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

Selectable with Fields crashes with invalid prefix ContextualMethodType when selectDynamic has implicit context arguments #22023

Open
soronpo opened this issue Nov 25, 2024 · 3 comments
Assignees
Labels
area:named-tuples Issues tied to the named tuples feature. area:typer itype:bug itype:crash regression This worked in a previous version but doesn't anymore stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced

Comments

@soronpo
Copy link
Contributor

soronpo commented Nov 25, 2024

Compiler version

v3.6.2-RC1

Minimized code

trait Ctx
class Foo extends Selectable:
  type Fields = (bar: Int, baz: Int)
  def selectDynamic(fieldName: String)(using Ctx): Any = ???

val f = Foo()
val bar = f.bar

Output (click arrow to expand)

[error] java.lang.AssertionError: assertion failed: invalid prefix ContextualMethodType(List(x$2), List(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),trait Ctx)), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Any))
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.core.Types$NamedType.<init>(Types.scala:2313)
[error] dotty.tools.dotc.core.Types$TermRef.<init>(Types.scala:2918)
[error] dotty.tools.dotc.core.Types$CachedTermRef.<init>(Types.scala:2999)
[error] dotty.tools.dotc.core.Uniques$NamedTypeUniques.newType$1(Uniques.scala:44)
[error] dotty.tools.dotc.core.Uniques$NamedTypeUniques.enterIfNew(Uniques.scala:46)
[error] dotty.tools.dotc.core.Types$TermRef$.apply(Types.scala:3053)
[error] dotty.tools.dotc.core.Types$TermRef$.apply(Types.scala:3059)
[error] dotty.tools.dotc.ast.tpd$TreeOps$.select$extension(tpd.scala:941)
[error] dotty.tools.dotc.ast.tpd$TreeOps$.cast$extension(tpd.scala:1039)
[error] dotty.tools.dotc.ast.tpd$TreeOps$.cast$extension(tpd.scala:1034)
[error] dotty.tools.dotc.ast.tpd$TreeOps$.ensureConforms$extension(tpd.scala:1048)
[error] dotty.tools.dotc.typer.Typer.trySelectable$1(Typer.scala:876)
[error] dotty.tools.dotc.typer.Typer.typedSelectWithAdapt(Typer.scala:906)
[error] dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:993)
[error] dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:1031)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3468)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3577)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3655)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3659)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3770)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1765)
[error] dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1755)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1765)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:2123)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:2123)
[error] dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:2131)
[error] dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:2150)
[error] dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:2151)
[error] dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:2162)
[error] dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1808)
[error] dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1814)
[error] dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:823)
[error] dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:990)
[error] dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:859)
[error] dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
[error] dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
[error] dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
[error] dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
[error] dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3440)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3465)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3577)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3655)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3659)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3681)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3727)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3160)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3481)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3485)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3577)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3655)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3659)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3681)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3727)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3293)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3527)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3578)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3655)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3659)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3770)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:507)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
[error] dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
[error] scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
[error] scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
[error] scala.collection.immutable.List.prependedAll(List.scala:152)
[error] scala.collection.immutable.List$.from(List.scala:685)
[error] scala.collection.immutable.List$.from(List.scala:682)
[error] scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
[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:1323)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:396)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:282)
[error] dotty.tools.dotc.Run.compile(Run.scala:267)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
[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:196)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:252)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:186)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:166)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:241)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:166)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:214)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:542)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:542)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$3(Incremental.scala:178)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$3$adapted(Incremental.scala:176)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:454)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:117)
[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:265)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:409)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:496)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:396)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:204)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:542)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:496)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:433)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2419)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2369)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:41)
[error] sbt.internal.io.Retry$.apply(Retry.scala:47)
[error] sbt.internal.io.Retry$.apply(Retry.scala:29)
[error] sbt.internal.io.Retry$.apply(Retry.scala:24)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:41)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2367)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] sbt.Execute.work(Execute.scala:292)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error] java.base/java.lang.Thread.run(Thread.java:840)
[error]
[error] stack trace is suppressed; run last lib / Test / compileIncremental for the full output
[error] (lib / Test / compileIncremental) java.lang.AssertionError: assertion failed: invalid prefix ContextualMethodType(List(x$2), List(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),trait Ctx)), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Any))
@soronpo soronpo added itype:bug itype:crash area:named-tuples Issues tied to the named tuples feature. labels Nov 25, 2024
@soronpo soronpo changed the title Selectable with Fields crashes with invalid prefix ContextualMethodType when selectDynamic has given context arguments Selectable with Fields crashes with invalid prefix ContextualMethodType when selectDynamic has implicit context arguments Nov 25, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Nov 26, 2024

Note: this only started crashing since 3.5.0, although it has not been compiling for earlier versions.

scala-cli compile repro.scala -S 3.4.3

gives

[error] ./repro.scala:4:1
[error] '=>' expected, but 'end of statement' found
[error]   def selectDynamic(fieldName: String)(using Ctx): Any = ???
[error] ^^^
[error] ./repro.scala:7:11
[error] value bar is not a member of Foo
[error] val bar = f.bar
[error]           ^^^^^

So technically, the crash could be considered a regression.

Last good stable version: 3.4.3
First bad stable version: 3.5.0

@Gedochao Gedochao added regression This worked in a previous version but doesn't anymore area:typer labels Nov 26, 2024
@Gedochao Gedochao added the stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced label Nov 26, 2024
@soronpo
Copy link
Contributor Author

soronpo commented Nov 26, 2024

This is not a real regression because named tuple syntax did not exist until 3.5 (as experimental). So no bisect is needed. The implementation needs to be fixed to account for the implicit arguments in selectDynamic.

soronpo pushed a commit to DFiantHDL/DFHDL that referenced this issue Nov 27, 2024
@Gedochao
Copy link
Contributor

This is not a real regression because named tuple syntax did not exist until 3.5 (as experimental).

I know, but a compiler crash was still introduced. Grey zone, I know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:named-tuples Issues tied to the named tuples feature. area:typer itype:bug itype:crash regression This worked in a previous version but doesn't anymore stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced
Projects
None yet
Development

No branches or pull requests

3 participants