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

Crash when overriding an inline method under specific conditions #13586

Closed
abgruszecki opened this issue Sep 22, 2021 · 3 comments · Fixed by #13649
Closed

Crash when overriding an inline method under specific conditions #13586

abgruszecki opened this issue Sep 22, 2021 · 3 comments · Fixed by #13649

Comments

@abgruszecki
Copy link
Contributor

abgruszecki commented Sep 22, 2021

Compiler version

Master.

Minimized code

// scratch0.scala
import scala.quoted._

object Position {
  def withPosition[T](fun: Expr[Unit => T])(using quotes: Quotes, typeOfT: Type[T]): Expr[T] =
    '{${fun}.apply(null)}
}
// scratch.scala
class Foo {
 inline def test(): Unit = {
   ${ Position.withPosition[Unit]('{ _ => this }) }
 }
}

class Bar extends Foo {
  def test(s: String) =
    super.test()
}

Output (click arrow to expand)

Compiling the files crashes. The crash is caused by the super.test call in test. All of super, this, inline seem necessary to trigger the crash.

// scalac scratch0.scala scratch.scala
Unexpected tree in genLoad: Super(This(Ident()),Ident())/class dotty.tools.dotc.ast.Trees$Super at: [151..156]
Error while emitting scratch.scala
Exception in thread "main" java.lang.RuntimeException: Unexpected tree in genLoad: Super(This(Ident()),Ident())/class dotty.tools.dotc.ast.Trees$Super at: [151..156] while compiling scratch0.scala, scratch.scala
java.lang.RuntimeException: Unexpected tree in genLoad: Super(This(Ident()),Ident())/class dotty.tools.dotc.ast.Trees$Super at: [151..156]
	at dotty.tools.backend.jvm.BCodeHelpers.abort(BCodeHelpers.scala:949)
	at dotty.tools.backend.jvm.BCodeHelpers.abort$(BCodeHelpers.scala:43)
	at dotty.tools.backend.jvm.GenBCodePipeline.abort(GenBCode.scala:111)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:454)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:285)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadQualifier(BCodeBodyBuilder.scala:1111)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genTypeApply(BCodeBodyBuilder.scala:638)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:452)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:305)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genStat(BCodeBodyBuilder.scala:111)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlock$$anonfun$1(BCodeBodyBuilder.scala:1019)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlock(BCodeBodyBuilder.scala:1019)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:432)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:766)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:801)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:609)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen$$anonfun$1(BCodeSkelBuilder.scala:615)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:615)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:230)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.visit(GenBCode.scala:259)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.run(GenBCode.scala:224)
	at dotty.tools.backend.jvm.GenBCodePipeline.buildAndSendToDisk(GenBCode.scala:559)
	at dotty.tools.backend.jvm.GenBCodePipeline.run(GenBCode.scala:525)
	at dotty.tools.backend.jvm.GenBCode.run(GenBCode.scala:63)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:308)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:309)
	at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:71)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:261)
	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:272)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:289)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:228)
	at dotty.tools.dotc.Driver.finish(Driver.scala:60)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:40)
	at dotty.tools.dotc.Driver.process(Driver.scala:199)
	at dotty.tools.dotc.Driver.process(Driver.scala:167)
	at dotty.tools.dotc.Driver.process(Driver.scala:179)
	at dotty.tools.dotc.Driver.main(Driver.scala:209)
	at dotty.tools.dotc.Main.main(Main.scala)
@abgruszecki
Copy link
Contributor Author

@nicolasstucki sorry for the unminimised example - I just wanted to get this off my mind. I'll minimise it as soon as I find the time.

@abgruszecki
Copy link
Contributor Author

Ok, turns out I have some time now - the examples are minimised.

@nicolasstucki
Copy link
Contributor

Minimized to

class Foo:
 inline def test(): Unit = this

class Bar extends Foo:
  def test(s: String) = super.test()

This issue is that when we inline we generate the binding val Foo_this: Bar.this = super instead of val Foo_this: Bar.this = this.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Oct 1, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
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.

3 participants