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

Inline unapply with leading contextual parameter used as extractor crashes compiler #12991

Closed
prolativ opened this issue Jul 1, 2021 · 0 comments · Fixed by #15583 or #16358
Closed

Comments

@prolativ
Copy link
Contributor

prolativ commented Jul 1, 2021

Compiler version

3.0.1-RC2

Minimized code

object Foo:
  inline def unapply(using String)(i: Int): Some[Int] = Some(i)

given String = ""

val i = 10 match
  case Foo(x) => x

Output (click arrow to expand)

Exception in thread "main" java.util.NoSuchElementException: head of empty list
	at scala.collection.immutable.Nil$.head(List.scala:662)
	at scala.collection.immutable.Nil$.head(List.scala:661)
	at dotty.tools.dotc.typer.Inliner.computeParamBindings(Inliner.scala:522)
	at dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:745)
	at dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:153)
	at dotty.tools.dotc.typer.Inliner$.$anonfun$4(Inliner.scala:207)
	at dotty.tools.dotc.ast.tpd$.DefDef(tpd.scala:285)
	at dotty.tools.dotc.typer.Inliner$.inlinedUnapply(Inliner.scala:208)
	at dotty.tools.dotc.typer.Typer$$anon$1.transform(Typer.scala:1588)
	at dotty.tools.dotc.typer.Typer.caseRest$1(Typer.scala:1615)
	at dotty.tools.dotc.typer.Typer.typedCase(Typer.scala:1633)
	at dotty.tools.dotc.typer.Typer.typedCases$$anonfun$1(Typer.scala:1563)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:92)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:108)
	at dotty.tools.dotc.typer.Typer.typedCases(Typer.scala:1565)
	at dotty.tools.dotc.typer.Typer.$anonfun$20(Typer.scala:1555)
	at dotty.tools.dotc.typer.Applications.harmonic(Applications.scala:2186)
	at dotty.tools.dotc.typer.Applications.harmonic$(Applications.scala:316)
	at dotty.tools.dotc.typer.Typer.harmonic(Typer.scala:106)
	at dotty.tools.dotc.typer.Typer.typedMatchFinish(Typer.scala:1555)
	at dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:1511)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2709)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1394)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1381)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1394)
	at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1546)
	at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:225)
	at dotty.tools.dotc.typer.Namer.typedAheadRhs$2(Namer.scala:1546)
	at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1554)
	at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1581)
	at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1582)
	at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1593)
	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1602)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:699)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:826)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:727)
	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:2637)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2662)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2849)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2899)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2354)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2683)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2687)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2757)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2849)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2899)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2477)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2728)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2758)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2823)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2827)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2943)
	at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:43)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
	at dotty.tools.repl.REPLFrontEnd.runOn(ReplFrontEnd.scala:23)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205)
	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:216)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:224)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:231)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:172)
	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:152)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:162)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:249)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:212)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:146)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:149)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:168)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:149)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:115)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)

The code compiles successfully if we either make unapply non-inlined or put the contextual parameter at the end instead.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 26, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 27, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 27, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 27, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 29, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Oct 8, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 24, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 3, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 13, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 4, 2022
We patch the crash in the compiler but do not support this feature yet.

To support it see scala#13158

Fixes scala#12991
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 4, 2022
We patch the crash in the compiler but do not support this feature yet.

To support it see scala#13158

Fixes scala#12991
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 17, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 17, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 18, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 7, 2022
* Fixes the computation of the inline unapply temporary unanimous unapply placeholder
* Handle leading given parameters in inline unapplies

Fixes scala#8577
Fixes scala#12991
Fixes scala#15188
nicolasstucki added a commit that referenced this issue Dec 7, 2022
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
* Fixes the computation of the inline unapply temporary unanimous unapply placeholder
* Handle leading given parameters in inline unapplies

Fixes scala#8577
Fixes scala#12991
Fixes scala#15188
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment