Skip to content

RuntimeError in backend when with implicit conversions on super #5007

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

Closed
sir-wabbit opened this issue Aug 24, 2018 · 4 comments
Closed

RuntimeError in backend when with implicit conversions on super #5007

sir-wabbit opened this issue Aug 24, 2018 · 4 comments
Assignees

Comments

@sir-wabbit
Copy link

class I0 {
  super.+("")
}
Unexpected tree in genLoad: Super(This(Ident()),Ident())/class dotty.tools.dotc.ast.Trees$Super at: [11..16]
exception occurred while compiling RE-341cc574ffab7ad1cca7c0683c727f4cd8ca9f68.scala
Exception in thread "main" java.lang.RuntimeException: Unexpected tree in genLoad: Super(This(Ident()),Ident())/class dotty.tools.dotc.ast.Trees$Super at: [11..16]
	at dotty.tools.backend.jvm.DottyBackendInterface.abort(DottyBackendInterface.scala:394)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:430)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadArguments$$anonfun$1(BCodeBodyBuilder.scala:1018)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadArguments(BCodeBodyBuilder.scala:1018)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genNormalMethodCall$1(BCodeBodyBuilder.scala:725)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:754)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:337)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:290)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genStat(BCodeBodyBuilder.scala:89)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genNormalBlock$2$$anonfun$1(BCodeBodyBuilder.scala:860)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genNormalBlock$1(BCodeBodyBuilder.scala:860)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlock(BCodeBodyBuilder.scala:892)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:408)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genStat(BCodeBodyBuilder.scala:89)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genNormalBlock$2$$anonfun$1(BCodeBodyBuilder.scala:860)

RE-341cc574ffab7ad1cca7c0683c727f4cd8ca9f68

@nicolasstucki
Copy link
Contributor

The issue is that we try to find an implicit conversion for the tree of super to have the method +. Placing super as argument which is not a correct tree.

class I0 {
  implicit def foo(any: Any): String = ()
  super.+("")
}
result of Foo.scala after frontend:
package <empty> {
  class I0() extends Object() { 
    implicit def foo(any: Any): String = this.foo(())
    this.foo(super).+("")
  }
}

I imagine that we simply should not try to do implicit conversions on Super trees.

@sir-wabbit
Copy link
Author

https://github.com/lampepfl/dotty/blob/master/tests/untried/neg/t5063.scala
It looks like the same snippet was imported from scala/tests back in 2014 but was never tried.

@Blaisorblade
Copy link
Contributor

@alexknvl Thanks for the pointer!

I imagine that we simply should not try to do implicit conversions on Super trees.

That's indeed the scalac fix to scala/bug#5063 (comment).

@Blaisorblade
Copy link
Contributor

And if we try the same thing:

diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
index feb6bc391..546cce74a 100644
--- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
@@ -552,6 +552,7 @@ trait Implicits { self: Typer =>
         || (from.tpe isRef defn.NothingClass)
         || (from.tpe isRef defn.NullClass)
         || !(ctx.mode is Mode.ImplicitsEnabled)
+        || from.isInstanceOf[Super]
         || (from.tpe eq NoPrefix)) NoMatchingImplicitsFailure
     else {
       def adjust(to: Type) = to.stripTypeVar.widenExpr match {

we get:

scala> class I0 {
     |   super.+("")
     | }
2 |  super.+("")
  |  ^^^^^^^
  | value `+` is not a member of Object - did you mean `Object(I0.super).eq`?

@Blaisorblade Blaisorblade self-assigned this Aug 26, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
Based on scala/scala@bed3304bf86 and Nicolas' suggestion.
@Blaisorblade Blaisorblade changed the title RuntimeError in backend RuntimeError in backend when with implicit conversions on super Aug 26, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
Based on scala/scala@bed3304bf86 and Nicolas' suggestion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants