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

Workaround protected[this] bug?

3 replies
nicolas.oury@gm...
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
Dear all,
I am blocked on a bug that I think is an instance of this:
https://issues.scala-lang.org/browse/SI-3272
trait A { trait C[+T] {    protected[this] def f(t: T) {} }   trait D[T] extends C[T] {   def g(t: T) { f(t) }  } }
My understanding is that it should compile.
Is there any way (even very hackish) to modify my program so I can go on?
Do we know what is the last version of the compiler without that bug?

Best regards,
Nicolas.
milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Workaround protected[this] bug?

On Wed, Oct 5, 2011 at 10:07 AM, nicolas.oury@gmail.com
wrote:
> Dear all,
> I am blocked on a bug that I think is an instance of this:
> https://issues.scala-lang.org/browse/SI-3272
> trait A {
>  trait C[+T] {
>    protected[this] def f(t: T) {}
>  }
>
>  trait D[T] extends C[T] {
>    def g(t: T) { f(t) }
>  }
> }
> My understanding is that it should compile.
> Is there any way (even very hackish) to modify my program so I can go on?
> Do we know what is the last version of the compiler without that bug?

Does this work for you?

trait C[+T] {
protected[this] def f(t: T @uncheckedVariance) {}
}

Cheers,

Miles

nicolas.oury@gm...
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
Re: Workaround protected[this] bug?
scala>  trait C[+T] {     |   protected[this] def f(t: T @uncheckedVariance) {}     |  }<console>:8: error: not found: type uncheckedVariance         protected[this] def f(t: T @uncheckedVariance) {}                                      ^No, but it looks promising.
(Currently, I have removed the enclosing traits that were just used for top-level modularity.  But with a hack like this, I could type check without the enclosing traits and when it is correct,  put back the enclosing trait + unsafeAnnotations)
milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Workaround protected[this] bug?

On Wed, Oct 5, 2011 at 10:39 AM, nicolas.oury@gmail.com
wrote:
> scala>  trait C[+T] {
>      |   protected[this] def f(t: T @uncheckedVariance) {}
>      |  }
> :8: error: not found: type uncheckedVariance
>          protected[this] def f(t: T @uncheckedVariance) {}
>                                      ^
> No, but it looks promising.

You need,

import scala.annotation.unchecked.uncheckedVariance

as well ;-)

Cheers,

Miles

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