Skip to content

Crash: completing val XXXXX in wrong run 3, was created in 2 while compiling #13821

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

Open
soronpo opened this issue Oct 26, 2021 · 3 comments
Open
Labels

Comments

@soronpo
Copy link
Contributor

soronpo commented Oct 26, 2021

This crash is dependent on various things that only when applied together trigger it (probably by affecting compilation order).
I did not find a way to minimize it further.
My original codebase currently works-around 2 other similar crashes that give off different reports from a wrong run, but I have yet to minimize them and will only do so once this is fixed since the problem might be related (this is a very difficult minimization).

Compiler version

v3.1.0

Minimized code

Minimized project available at: https://github.com/soronpo/dottybug/tree/wrong_run_crash

DFBits.scala

type DFBits = DFType

object DFBits:
  def apply(width: Any): Unit = {}
  val y: DFToken = ???
  y.width

  trait Candidate
  object Candidate:
    given Candidate = ???

    import DFVal.bits
    val x: IRToken = ???
    x.bits

  object Conversions:
    implicit def conv[R](from: R)(using Candidate): DFVal = ???
end DFBits

DFVal.scala

trait DFType

trait IRToken
extension (token: IRToken) def bits: Unit = ???

trait DFVal
object DFVal:
  export DFBits.Conversions.*
  extension (dfVal: DFVal)
    def width(using Width): Any = ???
    def bits(using Width): Unit = DFBits(dfVal.width)

trait DFToken
extension (token: DFToken) def width(using Width): Any = ???

import scala.quoted.*
trait Width
transparent inline given f: Width = ${ getWidthMacro }
def getWidthMacro(using Quotes): Expr[Width] =
  '{ new Width {} }

Output (click arrow to expand)

[info] exception occurred while typechecking C:\Users\oronpo\IdeaProjects\dottybug\src\main\scala\DFBits.scala
java.lang.AssertionError: assertion failed: completing val given_Candidate in wrong run 3, was created in 2 while compiling C:\Users\oronpo\IdeaProjects\dottybug\src\main\scala\DFBits.scala, C:\Users\oronpo\IdeaProjects\dottybug\src\main\scala\DFVal.scala
[error] ## Exception when compiling 2 sources to C:\Users\oronpo\IdeaProjects\dottybug\target\scala-3.1.0\classes
[error] java.lang.AssertionError: assertion failed: completing val given_Candidate in wrong run 3, was created in 2
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:775)
[error] dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
[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.Types$TermRef.underlying(Types.scala:2619)
[error] dotty.tools.dotc.core.Types$Type.widen(Types.scala:1211)
[error] dotty.tools.dotc.typer.Implicits$ImplicitRefs.candidateKind$1(Implicits.scala:227)
[error] dotty.tools.dotc.typer.Implicits$ImplicitRefs.tryCandidate$1(Implicits.scala:255)
[error] dotty.tools.dotc.typer.Implicits$ImplicitRefs.filterMatching$$anonfun$2(Implicits.scala:264)
[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.Implicits$ImplicitRefs.filterMatching(Implicits.scala:264)
[error] dotty.tools.dotc.typer.Implicits$OfTypeImplicits.eligible(Implicits.scala:286)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1390)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1399)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1424)
[error] dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:990)
[error] dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:771)
[error] dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:107)
[error] dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:845)
[error] dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:771)
[error] dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:107)
[error] dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3346)
[error] dotty.tools.dotc.typer.Typer.addImplicitArgs$3(Typer.scala:3382)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$2(Typer.scala:3462)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3660)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3873)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3224)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] dotty.tools.dotc.typer.Implicits.tryConversion$1(Implicits.scala:1056)
[error] dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1087)
[error] dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:771)
[error] dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:107)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1137)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1216)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1384)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1391)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1399)
[error] dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1424)
[error] dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:990)
[error] dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:771)
[error] dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:107)
[error] dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:817)
[error] dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:771)
[error] dotty.tools.dotc.typer.Typer.inferView(Typer.scala:107)
[error] dotty.tools.dotc.typer.Typer.adaptToSubType$1(Typer.scala:3770)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgsOther$4(Typer.scala:3592)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3682)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3873)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3224)
[error] dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:433)
[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.<init>(Applications.scala:735)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:852)
[error] dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1060)
[error] dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:317)
[error] dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:107)
[error] dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:907)
[error] dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:986)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3011)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:997)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1035)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:317)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:107)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2755)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] dotty.tools.dotc.typer.Applications.extMethodApply(Applications.scala:2229)
[error] dotty.tools.dotc.typer.Applications.extMethodApply$(Applications.scala:317)
[error] dotty.tools.dotc.typer.Typer.extMethodApply(Typer.scala:107)
[error] dotty.tools.dotc.typer.Typer.tryExtension$1(Typer.scala:3138)
[error] dotty.tools.dotc.typer.Typer.tryExtensionOrConversion(Typer.scala:3149)
[error] dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:587)
[error] dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:626)
[error] dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:663)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2725)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2936)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2409)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2743)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2747)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2409)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2743)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2747)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2409)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2743)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2747)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2532)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2788)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3003)
[error] dotty.tools.dotc.typer.TyperPhase.liftedTree1$1(TyperPhase.scala:56)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:62)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:63)
[error] dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$1(TyperPhase.scala:105)
[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:105)
[error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:261)
[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$5(Run.scala:272)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
[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:289)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:228)
[error] dotty.tools.dotc.Driver.finish(Driver.scala:60)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:40)
[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:175)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:173)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:459)
[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:414)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:501)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:167)
[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:2357)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2314)
[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:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2310)
[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.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] java.base/java.lang.Thread.run(Thread.java:829)
[error]
[error] stack trace is suppressed; run 'last Compile / compileIncremental' for the full output
[error] (Compile / compileIncremental) java.lang.AssertionError: assertion failed: completing val given_Candidate in wrong run 3, was created in 2
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Oct 27, 2021

Minimized slightly to

type DFBits = Long // why is this needed?

object DFBits:
  def a: Unit = f // forces suspension of this compilation unit in typer
  def b: DFVal = 2 // uses implicit conversion `DFVal.conv`

  trait Candidate
  object Candidate:
    given candidate: Candidate = ??? // completed in run 3 but created in run 2
end DFBits

trait DFVal
object DFVal extends Conversions
trait Conversions:
  given conv(using DFBits.Candidate): Conversion[Int, DFVal] = ???

import scala.quoted.*
transparent inline def f: Short = ${ getWidthMacro }
private def getWidthMacro(using Quotes): Expr[Short] = '{ ??? }
java.lang.AssertionError: assertion failed: completing val candidate in wrong run 3, was created in 2
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:776)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:168)
        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.Types$TermRef.underlying(Types.scala:2633)
        at dotty.tools.dotc.core.Types$Type.widen(Types.scala:1214)
        at dotty.tools.dotc.typer.Implicits$ImplicitRefs.candidateKind$1(Implicits.scala:227)
        at dotty.tools.dotc.typer.Implicits$ImplicitRefs.tryCandidate$1(Implicits.zscala:255)
        at dotty.tools.dotc.typer.Implicits$ImplicitRefs.filterMatching$$anonfun$2(Implicits.scala:264)
        ...

@soronpo
Copy link
Contributor Author

soronpo commented Oct 27, 2021

Thanks. Yeah, the thing that is really surprising is the type DFBits = alias. So weird.

@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices and removed area:metaprogramming labels Feb 7, 2022
@soronpo
Copy link
Contributor Author

soronpo commented Jun 6, 2025

Still crashes in 3.7.1
cc @Gedochao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants