Skip to content

Least upper bound bug? Analyzer and CFE infer "Function" #525

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

Open
ds84182 opened this issue Aug 14, 2019 · 1 comment
Open

Least upper bound bug? Analyzer and CFE infer "Function" #525

ds84182 opened this issue Aug 14, 2019 · 1 comment
Labels
feature Proposed language feature that solves one or more problems least-upper-bound Proposals about improvements of the LUB algorithm

Comments

@ds84182
Copy link

ds84182 commented Aug 14, 2019

Try this in DartPad:

Future<void> a(String f) async {}
void b([String f]) {}

void foo<T>(T a, T b) {
  print(T);
}

void main() {
  foo(a, b);
}

I would expect the LUB of (String) -> Future<void> and ([String]) -> void to be (String) -> void. Manually providing the type argument <void Function(String)> to foo doesn't cause any errors at runtime.

Is this an implementation error or a language issue?

cc @eernstg

@eernstg
Copy link
Member

eernstg commented Aug 14, 2019

The language specification section 'Least Upper Bounds' specifies rules for computing the upper and lower bounds, but those rules have been updated in implementations, and the current ones are not yet integrated into the language specification. See here for upcoming rules, including non-nullability.

In any case, both rulesets have the property that they yield Function when the least upper bound of two function types with distinct numbers of required parameters is computed.

But it is indeed true that void Function([String]) is a subtype of void Function(String), so the algorithm could be improved by taking this into account. It's useful to have this issue to remind us of that fact.

In any case, it will not be a least upper bound algorithm, because the computation for two interface types uses the tie-breaker rule described at the beginning of the 'Least Upper Bounds' section in the language specification.

@eernstg eernstg added the feature Proposed language feature that solves one or more problems label Aug 14, 2019
@eernstg eernstg added the least-upper-bound Proposals about improvements of the LUB algorithm label Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems least-upper-bound Proposals about improvements of the LUB algorithm
Projects
None yet
Development

No branches or pull requests

2 participants