Skip to content
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

relax function subtyping #2706

Closed
sigmundch opened this issue Apr 24, 2012 · 9 comments
Closed

relax function subtyping #2706

sigmundch opened this issue Apr 24, 2012 · 9 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@sigmundch
Copy link
Member

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).

@DartBot
Copy link

DartBot commented Apr 24, 2012

This comment was originally written by @seaneagan


this is very similar to issue #1826 (though possibly more well articulated)

@sigmundch
Copy link
Member Author

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)

@gbracha
Copy link
Contributor

gbracha commented Apr 29, 2012

 I think we once planned on having a more liberal rule as you suggest, but there were implementation concerns. I need to check with the VM team on this. Other than that, I'm fine with it.


Set owner to @gbracha.
Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented May 8, 2012

Issue #2824 has been merged into this issue.

@gbracha
Copy link
Contributor

gbracha commented May 24, 2012

Added this to the Later milestone.

@gbracha
Copy link
Contributor

gbracha commented May 24, 2012

Issue #1827 has been merged into this issue.

@lrhn
Copy link
Member

lrhn commented Jan 4, 2013

Issue #7680 has been merged into this issue.

@gbracha
Copy link
Contributor

gbracha commented Jan 8, 2013

Issue #7777 has been merged into this issue.


cc @peter-ahe-google.
cc @larsbak.

@gbracha
Copy link
Contributor

gbracha commented Jul 2, 2013

Added Done label.

@sigmundch sigmundch added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jul 2, 2013
@sigmundch sigmundch added this to the Later milestone Jul 2, 2013
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants