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

"assertion failed while typechecking" crash due to a missing implicit, when certain unrelated given and implicit def are in scope. #19328

Closed
raquo opened this issue Dec 23, 2023 · 2 comments · Fixed by #19329

Comments

@raquo
Copy link
Contributor

raquo commented Dec 23, 2023

Compiler version

3.3.1

The good news is that this appears to be fixed in nightly, I tested that 3.4.0-RC1-bin-20231219-eae8831-NIGHTLY does not crash.

I'm still filing the issue because the reproduction is small and consistent, and maybe you'll want to add this to your tests, or maybe it'll help in debugging any related issues. I couldn't find an existing report for this exact issue, but I easily could have missed it.

Minimized code

    trait Foo[B]
    given foo[C]: Foo[C] = new Foo
    
    type Id[A] = A

    implicit def wrapId[A](a: A): Id[A] = a
    
    // the `Conversion` below also fixes the error if used instead of `implicit def` above.
    // given wrapId[A]: Conversion[A, Id[A]] with
    //   def apply(x: A): Id[A] = x

    def bar(using bool: Boolean): Unit = ()

    bar // missing implicit: should give error, not a crash.

Output (click arrow to expand)

java.lang.AssertionError: assertion failed while typechecking rs$line$1
[error] java.lang.AssertionError: assertion failed
[error] 	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
[error] 	at dotty.tools.dotc.ast.tpd$.TypeApply(tpd.scala:60)
[error] 	at dotty.tools.dotc.ast.tpd$TreeOps$.appliedToTypeTrees$extension(tpd.scala:985)
[error] 	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4255)
[error] 	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3587)
[error] 	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:497)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:897)
[error] 	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:589)
[error] 	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:653)
[error] 	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:492)
[error] 	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:779)
[error] 	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:896)
[error] 	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1126)
[error] 	at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:352)
[error] 	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:969)
[error] 	at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1052)
[error] 	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3324)
[error] 	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1063)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
[error] 	at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
[error] 	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3048)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Implicits.tryConversion$1(Implicits.scala:1136)
[error] 	at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1167)
[error] 	at dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1242)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1341)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1511)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1539)
[error] 	at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1572)
[error] 	at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1060)
[error] 	at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:856)
[error] 	at dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.inferView(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits.viewExists(Implicits.scala:831)
[error] 	at dotty.tools.dotc.typer.Implicits.viewExists$(Implicits.scala:818)
[error] 	at dotty.tools.dotc.typer.Typer.viewExists(Typer.scala:116)
[error] 	at dotty.tools.dotc.typer.Implicits.ignoredConvertibleImplicits$1$$anonfun$3(Implicits.scala:960)
[error] 	at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
[error] 	at scala.collection.Iterator.isEmpty(Iterator.scala:466)
[error] 	at scala.collection.Iterator.isEmpty$(Iterator.scala:466)
[error] 	at scala.collection.AbstractIterator.isEmpty(Iterator.scala:1300)
[error] 	at scala.collection.View$Filter.isEmpty(View.scala:146)
[error] 	at scala.collection.IterableOnceOps.nonEmpty(IterableOnce.scala:833)
[error] 	at scala.collection.IterableOnceOps.nonEmpty$(IterableOnce.scala:833)
[error] 	at scala.collection.AbstractIterable.nonEmpty(Iterable.scala:933)
[error] 	at dotty.tools.dotc.reporting.MissingImplicitArgument.noChainConversionsNote$1(messages.scala:2838)
[error] 	at dotty.tools.dotc.reporting.MissingImplicitArgument.msgPostscript$$anonfun$4(messages.scala:2846)
[error] 	at scala.Option.orElse(Option.scala:477)
[error] 	at dotty.tools.dotc.reporting.MissingImplicitArgument.msgPostscript(messages.scala:2846)
[error] 	at dotty.tools.dotc.reporting.Message.message$$anonfun$1(Message.scala:345)
[error] 	at dotty.tools.dotc.reporting.Message.inMessageContext(Message.scala:341)
[error] 	at dotty.tools.dotc.reporting.Message.message(Message.scala:345)
[error] 	at dotty.tools.dotc.reporting.Message.isNonSensical(Message.scala:322)
[error] 	at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden(HideNonSensicalMessages.scala:16)
[error] 	at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden$(HideNonSensicalMessages.scala:10)
[error] 	at dotty.tools.repl.package$$anon$1.isHidden(package.scala:8)
[error] 	at dotty.tools.dotc.reporting.Reporter.issueUnconfigured(Reporter.scala:156)
[error] 	at dotty.tools.dotc.reporting.Reporter.go$1(Reporter.scala:181)
[error] 	at dotty.tools.dotc.reporting.Reporter.issueIfNotSuppressed(Reporter.scala:200)
[error] 	at dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:203)
[error] 	at dotty.tools.dotc.reporting.StoreReporter.report(StoreReporter.scala:50)
[error] 	at dotty.tools.dotc.report$.error(report.scala:68)
[error] 	at dotty.tools.dotc.typer.Typer.issueErrors$1$$anonfun$1(Typer.scala:3808)
[error] 	at scala.runtime.function.JProcedure3.apply(JProcedure3.java:15)
[error] 	at scala.runtime.function.JProcedure3.apply(JProcedure3.java:10)
[error] 	at scala.collection.LazyZip3.foreach(LazyZipOps.scala:248)
[error] 	at dotty.tools.dotc.typer.Typer.issueErrors$1(Typer.scala:3810)
[error] 	at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3832)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3849)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4038)
[error] 	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4268)
[error] 	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3587)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1653)
[error] 	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1643)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1653)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1906)
[error] 	at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:243)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1906)
[error] 	at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1914)
[error] 	at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1932)
[error] 	at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1933)
[error] 	at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1944)
[error] 	at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1691)
[error] 	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1698)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:787)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:934)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:814)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
[error] 	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2989)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3014)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
[error] 	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2669)
[error] 	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3036)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3040)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
[error] 	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3081)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
[error] 	at scala.Function0.apply$mcV$sp(Function0.scala:42)
[error] 	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.immutable.List.foreach(List.scala:333)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
[error] 	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
[error] 	at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
[error] 	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:200)
[error] 	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:87)
[error] 	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:307)
[error] 	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:269)
[error] 	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:169)
[error] 	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:172)
[error] 	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:211)
[error] 	at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:185)
[error] 	at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
[error] 	at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:185)
[error] 	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:172)
[error] 	at xsbt.ConsoleInterface.run(ConsoleInterface.java:52)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[error] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[error] 	at sbt.internal.inc.AnalyzingCompiler.invoke(AnalyzingCompiler.scala:329)
[error] 	at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:233)
[error] 	at sbt.Console.console0$1(Console.scala:65)
[error] 	at sbt.Console.$anonfun$apply$5(Console.scala:75)
[error] 	at sbt.Run$.executeSuccess(Run.scala:187)
[error] 	at sbt.Console.$anonfun$apply$4(Console.scala:75)
[error] 	at sbt.internal.util.Terminal.withRawInput(Terminal.scala:146)
[error] 	at sbt.internal.util.Terminal.withRawInput$(Terminal.scala:144)
[error] 	at sbt.internal.util.Terminal$ProxyTerminal$.withRawInput(Terminal.scala:424)
[error] 	at sbt.Console.$anonfun$apply$3(Console.scala:75)
[error] 	at sbt.internal.util.Terminal$TerminalImpl.withRawOutput(Terminal.scala:1028)
[error] 	at sbt.internal.util.Terminal$ProxyTerminal$.withRawOutput(Terminal.scala:463)
[error] 	at sbt.Console.apply(Console.scala:72)
[error] 	at sbt.Console.apply(Console.scala:50)
[error] 	at sbt.Console.apply(Console.scala:42)
[error] 	at sbt.Defaults$.$anonfun$consoleTask$1(Defaults.scala:2237)
[error] 	at sbt.Defaults$.$anonfun$consoleTask$1$adapted(Defaults.scala:2223)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] 	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] 	at sbt.Execute.work(Execute.scala:292)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error] 	at java.base/java.lang.Thread.run(Thread.java:833)
[error] (Compile / console) java.lang.AssertionError: assertion failed
@raquo raquo added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 23, 2023
@soronpo
Copy link
Contributor

soronpo commented Dec 23, 2023

If you have time submitting a PR with the added test could really help the compiler team.

@som-snytt
Copy link
Contributor

The canonical ticket is #18650 fixed in #18719
It was fixed on 3.4 and backported to 3.3.2 LTS.
There are several duplicate tickets.

@hamzaremmal hamzaremmal added stat:duplicate area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 30, 2023
nicolasstucki added a commit that referenced this issue Feb 1, 2024
Adding tests for crash reproduction #19328 that I reported, that was
already fixed in nightly.

I added the `pos` ones just in case, as protection against potential
regressions. So far I managed to reproduce the crash only when the
implicit was missing, as in `neg` tests. I can remove the `pos` tests if
you think these are excessive.

I ran only my own tests locally, they passed.

Fixes #19328

cc @soronpo
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur added a commit that referenced this issue Jul 1, 2024
…9328" to LTS (#20875)

Backports #19329 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants