Skip to content

Strong mode analyzer ignores function types in conditional operator #25248

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

Closed
lexaknyazev opened this issue Dec 14, 2015 · 6 comments
Closed
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on

Comments

@lexaknyazev
Copy link
Contributor

Dart VM version: 1.14.0-dev.4.0.
This is OK:

typedef int ProcessFunction(int v);
int foo(int a) => a * 2;
int bar(int b) => b * 3;

ProcessFunction process;

void main() {
  var t = true;
  if (t) process = foo;
  else process = bar;
}

However this

typedef int ProcessFunction(int v);
int foo(int a) => a * 2;
int bar(int b) => b * 3;

ProcessFunction process;

void main() {
  var t = true;
  process = t ? foo : bar;
}

results in WARNING: t ? foo : bar (Function) will need runtime check to cast to type (int) → int.

@leafpetersen
Copy link
Member

There are two related issues here. The first is that the analyzer (normal mode) does not currently implement least upper bound for function types, see: #23381 and #23663 .

The second is that we shouldn't really be using the dart spec version of least upper bound, since it produces very bad results in lots of places.

dart-archive/dev_compiler#288
#19425

Getting a DDC lub implemented is on my list of things to do fairly soon.

@jmesserly
Copy link

@leafpetersen is an improved LUB something we want to tackle in Q1?

@leafpetersen
Copy link
Member

Yes. It doesn't have to be complete, but the function case comes up surprisingly often, in addition to the EfficientLength kind of issue.

@jmesserly
Copy link

I've merged dart-archive/dev_compiler#288 into this issue. There's some useful discussion on that bug, but the code is part of analyzer now.

@jmesserly
Copy link

I think @munificent fixed the first part (LUB in normal mode) ... I think we still need a strong-mode LUB, as the spec version is not sound.

@jmesserly
Copy link

merging this into #25802

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on and removed Priority-Medium labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

5 participants