- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
findMember
Thu, 2009-07-02, 10:52
Hi,
while fixing #2116, I found the following. Given
trait A { def f(x: Int): Object }
class B extends A { def f(x: Int): String = "x" }
calling <BClassInfo>.findMember("f") returns
- before erasure only the overrding method, f:(x: Int)String
- after erasure both methods, f:(x: Int)String <and> f:(x: Int)Object
this is because matchesType is false after erasure. matchesType does
case _ =>
alwaysMatchSimple || tp1 =:= tp2
where by default, "alwaysMatchSimple = !phase.erasedTypes".
I fixed my ticked without touching findMember, but I'm not sure if the
described behavior is a feature or we need to correct it.
Lukas
while fixing #2116, I found the following. Given
trait A { def f(x: Int): Object }
class B extends A { def f(x: Int): String = "x" }
calling <BClassInfo>.findMember("f") returns
- before erasure only the overrding method, f:(x: Int)String
- after erasure both methods, f:(x: Int)String <and> f:(x: Int)Object
this is because matchesType is false after erasure. matchesType does
case _ =>
alwaysMatchSimple || tp1 =:= tp2
where by default, "alwaysMatchSimple = !phase.erasedTypes".
I fixed my ticked without touching findMember, but I'm not sure if the
described behavior is a feature or we need to correct it.
Lukas
Sun, 2009-07-05, 21:57
#2
Re: findMember
On Sun, Jul 5, 2009 at 22:34, martin odersky <martin.odersky@epfl.ch> wrote:
On Thu, Jul 2, 2009 at 11:52 AM, Lukas Rytz<lukas.rytz@epfl.ch> wrote:
> Hi,
>
> while fixing #2116, I found the following. Given
>
> trait A { def f(x: Int): Object }
> class B extends A { def f(x: Int): String = "x" }
>
> calling <BClassInfo>.findMember("f") returns
> - before erasure only the overrding method, f:(x: Int)String
> - after erasure both methods, f:(x: Int)String <and> f:(x: Int)Object
>
> this is because matchesType is false after erasure. matchesType does
> case _ =>
> alwaysMatchSimple || tp1 =:= tp2
> where by default, "alwaysMatchSimple = !phase.erasedTypes".
>
>
> I fixed my ticked without touching findMember, but I'm not sure if the
> described behavior is a feature or we need to correct it.
>
It's a feature. After erasure, the two findMembers are no longer in
overriding relationship. (after erasure, overriding is the way the JVM
sees it). That's why we need bridge methods.
But they are not in an overloading relationship, (Int):String is overriding(Int):Object, for instance
scala> class Base { def f(x: Int): Object = new Object } defined class Base
scala> class Sub extends Base { override def f(x: Int): String = "lskdjf" } defined class Sub
I think it's an error that both are returned before erasure.
Lukas
Sun, 2009-07-05, 22:07
#3
Re: findMember
On Sun, Jul 5, 2009 at 10:48 PM, Lukas Rytz wrote:
>
>
> On Sun, Jul 5, 2009 at 22:34, martin odersky wrote:
>>
>> On Thu, Jul 2, 2009 at 11:52 AM, Lukas Rytz wrote:
>> > Hi,
>> >
>> > while fixing #2116, I found the following. Given
>> >
>> > trait A { def f(x: Int): Object }
>> > class B extends A { def f(x: Int): String = "x" }
>> >
>> > calling .findMember("f") returns
>> > - before erasure only the overrding method, f:(x: Int)String
>> > - after erasure both methods, f:(x: Int)String f:(x: Int)Object
>> >
>> > this is because matchesType is false after erasure. matchesType does
>> > case _ =>
>> > alwaysMatchSimple || tp1 =:= tp2
>> > where by default, "alwaysMatchSimple = !phase.erasedTypes".
>> >
>> >
>> > I fixed my ticked without touching findMember, but I'm not sure if the
>> > described behavior is a feature or we need to correct it.
>> >
>> It's a feature. After erasure, the two findMembers are no longer in
>> overriding relationship. (after erasure, overriding is the way the JVM
>> sees it). That's why we need bridge methods.
>
> But they are not in an overloading relationship, (Int):String is overriding
> (Int):Object, for instance
Before erasure, yes, of course. After erasure, no.
Cheers
On Thu, Jul 2, 2009 at 11:52 AM, Lukas Rytz wrote:
> Hi,
>
> while fixing #2116, I found the following. Given
>
> trait A { def f(x: Int): Object }
> class B extends A { def f(x: Int): String = "x" }
>
> calling .findMember("f") returns
> - before erasure only the overrding method, f:(x: Int)String
> - after erasure both methods, f:(x: Int)String f:(x: Int)Object
>
> this is because matchesType is false after erasure. matchesType does
> case _ =>
> alwaysMatchSimple || tp1 =:= tp2
> where by default, "alwaysMatchSimple = !phase.erasedTypes".
>
>
> I fixed my ticked without touching findMember, but I'm not sure if the
> described behavior is a feature or we need to correct it.
>
It's a feature. After erasure, the two findMembers are no longer in
overriding relationship. (after erasure, overriding is the way the JVM
sees it). That's why we need bridge methods.
Cheers