Skip to content

Strong mode analyzer ignores function types in conditional operator #25248

Closed
@lexaknyazev

Description

@lexaknyazev

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.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions