This page is no longer maintained — Please continue to the home page at www.scala-lang.org

findMember

3 replies
rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
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
odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: findMember

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

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
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
odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
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

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland