Consider the following example:
== a.dart =============================
library a;
class A {
String toString() => _p();
String _p() => 'A';
}
== b.dart =============================
library b;
import 'a.dart';
class B extends A {
String _p() => 'B';
}
void main() {
print(new A());
print(new B());
}
When running b.dart it prints "A" and "A".
This is probably what one would expect from Java, where private methods are called based on the static type. I was surprised to find the same behaviour in Dart. Maybe the editor should show a warning in this case?
When moving the class A to the package b the output suddenly becomes "A" and "B". Again, this is probably expected, but I was surprised that a simple move of a class from a to b can subtly change its behaviour.
Long story short, this particular behaviour prevents me from subclassing SimpleConfiguration from the official unittest package. I want to redirect all output, but cannot replace the method _postMessage. Also I cannot just copy the class SimpleConfiguration, because it needs access to private fields in TestCase. Obviously I could ask the authors to make _postMessage public, but I am wondering if I am overseeing something obvious?
Lukas