Hi,
I think I may have encountered a bug or at least a limitation in implicit conversions and I was wondering why this is so. It seems implicit conversions are only inferred for member selections with an explicit target object, different from |this|, such as |a.foo| and not when the target object is |this| or when it is left implicit. I've tried to construct a small example that exhibits the same behaviour as in my actual code (which uses implicit conversions to insert the unrolling and rolling operations that witness the isomorphism between a recursive type and its unrolling). implicit def foo2bar(foo :Foo) :Bar = foo.bar class Foo(val bar :Bar) { def testCoercion ={ val a = this; a.baz /* here, foo2bar is inferred by the compiler, as expected */} def testCoercionThis = baz // --> error: not found: value baz def testCoercionThis = this.baz // --> error: value baz is not a member of Foo } class Bar { def baz = System.out.println("baz")} Obviously, this is a contrived example, but it would really be useful in my actual code (see my earlier post http://article.gmane.org/ gmane.comp.lang.scala/1956/match=hodgp and http://www.cs.kuleuven.be/ ~adriaan/?q=hodgp_scala I'm trying to get rid of |Fix()| and the indirection via the |out|- member, which would largely make up for the lack of recursive type synonyms). I guess this could also be used to implement a kind of poor man's forwarding. regards, adriaan |
Adriaan Moors wrote:
> Hi, > > I think I may have encountered a bug or at least a limitation in > implicit conversions and I was wondering why this is so. It seems > implicit conversions are only inferred for member selections with an > explicit target object, different from |this|, such as |a.foo| and not > when the target object is |this| or when it is left implicit. > Thanks for this observation. Indeed a view is not searched when the method name is a simple identifier. I still have to find out why no view is found when the prefix is `this'. In any case, I think you are right that we should correct this, so I classify these things as bugs. Cheers -- Martin > I've tried to construct a small example that exhibits the same > behaviour as in my actual code (which uses implicit conversions to > insert the unrolling and rolling operations that witness the > isomorphism between a recursive type and its unrolling). > > > implicit def foo2bar(foo :Foo) :Bar = foo.bar > > class Foo(val bar :Bar) { > def testCoercion ={ val a = this; a.baz /* here, foo2bar is > inferred by the compiler, as expected */} > def testCoercionThis = baz // --> error: not found: value baz > def testCoercionThis = this.baz // --> error: value baz is not a > member of Foo > } > > class Bar { def baz = System.out.println("baz")} > > > Obviously, this is a contrived example, but it would really be useful > in my actual code (see my earlier post http://article.gmane.org/ > gmane.comp.lang.scala/1956/match=hodgp and http://www.cs.kuleuven.be/ > ~adriaan/?q=hodgp_scala > I'm trying to get rid of |Fix()| and the indirection via the |out|- > member, which would largely make up for the lack of recursive type > synonyms). > > I guess this could also be used to implement a kind of poor man's > forwarding. > > regards, > adriaan > |
Free forum by Nabble | Edit this page |