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
Overriding a method C => A with a method C => B, where C is some value class and A and B are regular classes with B <: A, generates a broken forwarder. The forwarder attempts to box to the value class erasure's box and then cast to the value class box, producing a ClassCastException at runtime. Naturally, this affects overrides returning this.type as well. Tested with nightly Scala-2.11.0-SNAPSHOT.
objectValueClassForwarderVarianceextendsApp {
classBox(valvalue:Int) extendsAnyValtraitFoo {
defappend(box: Box):Foo
}
classBarextendsFoo {
overridedefappend(box: Box):Bar=this// produces bad forwarder
}
// throws ClassCastException: java.lang.Integer cannot be cast to _$Box
((newBar):Foo).append(newBox(0))
}
// boxes to value class erasure's box,// casts to value class box (fail),// then unboxes and forwards.
public ValueClassForwarderVariance$Foo append(int);
Code:0: aload_0
1: iload_1
2: invokestatic #20// Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;5: checkcast #22// class ValueClassForwarderVariance$Box8: invokevirtual #26// Method ValueClassForwarderVariance$Box.value:()I11: invokevirtual #28// Method append:(I)LValueClassForwarderVariance$Bar;14: areturn
The text was updated successfully, but these errors were encountered:
@paulp said:
Terminology note to submitter: that's a bridge method, not a forwarder. (It is true that it forwards, so it's not like it's a crazy choice of word, but it's confusing because we have other things called forwarders.)
Chris Sachs (c9r) said:
Good to know definitively about the bridge method terminology, I'd wondered. I was about to report that value class methods also forget their type parameter bounds, but I see you already found and fixed that one :) Thanks.
Overriding a method C => A with a method C => B, where C is some value class and A and B are regular classes with B <: A, generates a broken forwarder. The forwarder attempts to box to the value class erasure's box and then cast to the value class box, producing a ClassCastException at runtime. Naturally, this affects overrides returning this.type as well. Tested with nightly Scala-2.11.0-SNAPSHOT.
The text was updated successfully, but these errors were encountered: