Skip to content

Inconsistent type inference behavior of block-type vs expression-type closures #29606

Closed
@stereotype441

Description

@stereotype441

Consider the following code:

typedef num FunctionReturningNum();

main() {
  Object o = 1;
  FunctionReturningNum a = () => o;
  FunctionReturningNum b = () { return o; }
}

Type inference currently infers a return type of Object for the closure in a, and a return type of num for the closure in b.

The behavior of expression-type closures should be changed to match that of block-type closures.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onarea-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).language-strong-mode-polishlegacy-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