Aladdin - Scala Bugtracking
[#1170] project: compiler priority: high category: bug
submitter assigned to status date submitted
Sean Martin fixed 2007-06-06 11:53:34.0
subject big hole in this qualified private/protected
code
package test;

object Covariant {
  class Foo[+A] {
    private[this] var a : A = _
    def getA : A = a
    private[this] def setA(a : A) = this.a = a 

    trait Convert[B] {
      def b2a(b : B) : A
      def doit(b : B) = setA(b2a(b))
    }
  }
  abstract class AbstractTest {
    val a : Foo[AnyRef]
    val c = new a.Convert[Int] {
      def b2a(b : Int) : AnyRef = "hello"
    }
    val b : Int = 42
  }
  class Test extends AbstractTest {
    val a : Foo[Character] = new Foo[Character]
  }
  def main(args : Array[String]) : Unit = {
    val test = new Test
    test.c.doit(test.b)
    val x : Character = test.a.getA
    Console.println("XXX " + x)
  }
}


what happened
Class cast exception (String is not Character)

what expected Inner types (e.g., Convert[B] in Foo[A]) should not be allowed to access private[this]/protected[this] methods of parent unless they are also private[this]/protected[this] qualified. E.g., protected[this] trait Convert[B] { .... } Would be OK because then Convert could not be created from a Foo that undergoes subsumption.
[back to overview]
Changes of this bug report
Stephane  edited on  2007-06-26 15:03:14.0
Martin  edited on  2007-06-29 19:53:57.0