20540, "mppf", "When should shadowing occur for operator functions and methods?", "2022-08-29T17:57:59Z"
Summary of Problem
Before PR #20528, operators had the following shadowing behavior:
- if an operator method shadows an operator method, ambiguity
- if a non-method operator shadows an operator method, ambiguity
- if an operator method shadows an non-method operator, ambiguity
- if an non-method operator shadows an non-method operator, the inner one is chosen
After PR #20528, that behavior changes to choosing the inner one in all of the above cases.
Which behavior is the behavior we want?
Steps to Reproduce
Source Code:
module Library {
record R { var x: int; }
operator +(a: R, b: R) {
writeln("in Library plus");
return new R(a.x + b.x);
}
}
module Variant {
import Library.R;
operator R.+(a: R, b: R) {
writeln("in Variant plus");
return new R(a.x + b.x);
}
}
module Main {
use Library;
proc main() {
use Variant;
var x = new R(1);
var y = new R(2);
var z = x + y;
assert(z.x == 3);
}
}
Associated ~Future~ Test(s):
test/functions/operatorOverloads/shadowing-*
#20528