-
Notifications
You must be signed in to change notification settings - Fork 1.7k
relax function subtyping #2706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comment was originally written by @seaneagan this is very similar to issue #1826 (though possibly more well articulated) |
Thanks for the pointer to the other issue, did you mean issue #1827? (1826 seemed unrelated so I figured it might have been a typo) |
Issue #2824 has been merged into this issue. |
Added this to the Later milestone. |
Issue #1827 has been merged into this issue. |
Issue #7680 has been merged into this issue. |
Issue #7777 has been merged into this issue. cc @peter-ahe-google. |
Added Done label. |
I'd like to consider relaxing the function subtyping rules from Section 13.5 of the spec.
I recently run into limitations with the current rule that I think are unnecessary. Consider this example:
typedef Dynamic Fun1(Dynamic p);
typedef Dynamic Fun2([Dynamic p]);
f1(p) => print("1 $p");
f2([p=null]) => print("2 $p");
main() {
Fun1 test1 = f1;
Fun2 test2 = f2;
Fun1 test3 = f2; // error today, would be OK if we change the rules
Fun2 test4 = f1; // error today, should continue to be error
test1("hi1");
test2("hi2");
test3("hi3"); // this could be allowed if we change the rules.
test4("hi4");
test4(); // this error is correctly prevented by the current rules
}
In this example, the type system will give errors on the assignment of test3 and test4. I claim that test3 should be considered a valid assignment, but test4 continue to be an error.
In terms of the type system. Currently we compare these 2 types:
(T1, ... Tn, [Tx1 x1, ..., Txk xk]) -> T
(S1, ... Sn; [Sy1 y1; ..., Sym ym]) -> S
And we force that the total number of positional arguments (n) is the same.
I'd like to relax by considering the named arguments of the second type a possible replacement for missing positional arguments, that is:
(T1, ... Tn, [Tx1 x1, ..., Txk xk]) -> T
(S1, ... Sj; [Sy1 y1; ..., Sym ym]) -> S
The rules could check that j + ym >= n. Let yn be such that j+yn = n. Then compare (T1... Tn) with (S1 ... Sj Sy1 ... Syn).
The text was updated successfully, but these errors were encountered: