17134, “lydia-duncan”, “Fix type methods, inheritance, and going to the type’s definition point?”, “2021-02-09T18:36:50Z”
In discussing inheritance and operator methods, I discovered that the behavior of type methods and inheritance was different if the type method was called in the same scope as it was defined versus if it was called outside it. For example (originally from this comment), this code compiles and runs without issue:
module M {
class C {
var x: int;
proc type foo() { writeln("In C.foo()"); }
operator +(c1: C, c2: C) { return new C(c1.x + c2.x); }
}
class D: C { }
var myD = new D();
D.foo();
}
But this code does not:
module M {
class C {
var x: int;
proc type foo() { writeln("In C.foo()"); }
operator +(c1: C, c2: C) { return new C(c1.x + c2.x); }
}
}
module N {
import M.C;
class D: C { }
var myD = new D();
D.foo();
}
It seems to me like we should be able to resolve the inherited type call the same in both cases. At the very least, I think there should be some discussion on what the appropriate behavior is, even if the answer is “what currently happens”.