Aladdin - Scala Bugtracking
[#71] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Burak Martin fixed 2003-07-15 16:39:15.0
subject implementing abstract Java methods
code
// file 1 "gu/ga.scala" (it needs to under a package...)

package gu;

public abstract class ga1 {
    /*public*/ abstract String  foo(); // if you uncomment public, it works
    public void mymain() {
	System.out.println( foo() );
    }
    public ga1() {}
}

// ga2

object ga2 extends gu.ga1() {
  // implementation of foo()
  def foo():java.lang.String = "foo";
  // my main inherited
  def main( args:Array[String] ):Unit = {
    mymain ();
  }
}
what happened
>javac gu/ga1.java
>socos ga2.scala
>java ga2
Exception in thread "main" java.lang.AbstractMethodError: gu.ga1.foo()Ljava/lang/String;
	at gu.ga1.mymain(ga1.java:8)
	at ga2$.main(ga2.scala)
	at ga2.main(ga2.scala)
what expected "foo" being printed.
[back to overview]
Changes of this bug report
Matthias  edited on  2003-07-15 22:27:38.0
The expected behavior is a compile-time error! Method foo in gu.ga1 is protected; consequently, it will not be inherited to classes outside of the package gu. Therefore it is impossible to implement this abstract method in a subclass outside of the package gu. This is not Scala-specific; even in Java it will never be possible to implement foo in a class of the empty (top-level) package.

In Scala, protected is regarded as private since Scala does not have a notion of a package-private access. That's why the compiler has to emit an error message: "ga2 should be declared abstract, it does not implement foo...".

Martin  edited on  2003-07-16 14:17:04.0
The problem was that the class reader did not enter private members into the scope of their parents. I fixed that now.
Martin  edited on  2003-07-16 15:23:24.0