You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scala>classA(valx:Int) extendsAnyVal { defthis(s: String) =this(s.length) }
defined classA
scala>newA("a") ==newA("b")
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at scala.runtime.BoxesRunTime.unboxToInt(UnknownSource)
at .<init>(<console>:9)
at .<clinit>(<console>)
scala>classX(vala:Int) extendsAnyVal { defthis(x: String) =this(0) }
defined classX
scala>newX("").a
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at
Troublesome spots in the implementation:
https://github.com/scala/scala/blob/39fc4aa84/src/compiler/scala/tools/nsc/transform/Erasure.scala#L362
https://github.com/scala/scala/blob/39fc4aa84/src/compiler/scala/tools/nsc/transform/Erasure.scala#L1003
https://github.com/scala/scala/blob/39fc4aa84/src/compiler/scala/tools/nsc/transform/PostErasure.scala#L36
https://github.com/scala/scala/blob/39fc4aa84/src/compiler/scala/tools/nsc/transform/PostErasure.scala#L46
I tried to constrain these spots to only consider primary constructor, but this triggered a compiler crash which I'm yet to pin down.
A heavy handed approach would be to disallow secondary constructors for now.
The text was updated successfully, but these errors were encountered: