We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
trait A class B(val x: Int) { self: A => def this() = this() } val x = new B(2) with A val y = new B with A
and also
trait A class B { self: A => def this(x: Int) = this() } val x = new B(2) with A val y = new B with A
=== What is the expected behavior? === Since val x = new B(1,2) with A gives compile error:
val x = new B(1,2) with A
error: overloaded method constructor B with alternatives: (x: Int)B <and> ()B cannot be applied to (Int, Int) val x = new B(1,2) with A ^
Either a class using the overloaded constructor or compile-time error (rather than runtime)
=== What do you see instead? === Runtime error!
java.lang.VerifyError: (class: B, method: <init> signature: ()V) Expecting to find unitialized object on stack
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered:
Imported From: https://issues.scala-lang.org/browse/SI-4460?orig=1 Reporter: scoder
Sorry, something went wrong.
@magarciaEPFL said: The problem is the def this() = this(). Removing it does away with the VerifyError.
def this() = this()
VerifyError
Rephrasing the example:
trait A class B(val x: Int) { self: A => def this() = this() } object C extends B(2) with A { def main(args: Array[String]) { } }
we get the runtime error:
C:\temp\>java -verify -Xbootclasspath/a:Z:\scala-library.jar C Exception in thread "main" java.lang.VerifyError: (class: B, method: <init> signature: ()V) Expecting to find unitialized object on stack at C.main(bt4.scala)
Regarding classfile B, the difference between including or not def this() = this() is the public B(); below:
B
public B();
C:\temp\>javap -c B Compiled from "bt4.scala" public class B extends java.lang.Object implements scala.ScalaObject{ public int x(); // omitted public B(int); // omitted public B(); Code: 0: getstatic SI-27; //Field scala/Predef$$.MODULE$$:Lscala/Predef$$; 3: invokespecial SI-28; //Method scala/Predef$$."<init>":()V 6: return }
Classfile C (with or without def this() = this()) is:
C
C:\temp\>javap -c C Compiled from "bt4.scala" public final class C extends java.lang.Object{ public static final void main(java.lang.String[]); Code: 0: getstatic SI-11; //Field C$$.MODULE$$:LC$$; 3: aload_0 4: invokevirtual SI-13; //Method C$$.main:([Ljava/lang/String;)V 7: return public static final int x(); Code: 0: getstatic SI-11; //Field C$$.MODULE$$:LC$$; 3: invokevirtual SI-17; //Method C$$.x:()I 6: ireturn }
@retronym said: scala/scala#1689
retronym
No branches or pull requests
=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
and also
=== What is the expected behavior? ===
Since
val x = new B(1,2) with A
gives
compile error:
Either a class using the overloaded constructor or compile-time error (rather than runtime)
=== What do you see instead? ===
Runtime error!
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: