Skip to content

Analyzer fails to propery type check invocations of complex expressions whose type is a type parameter #56907

@stereotype441

Description

@stereotype441

This code is (correctly) rejected by both the analyzer and the CFE:

int test<T extends int Function(int)>(T Function() createT) {
  var tValue = createT();
  return tValue(''); // ERROR: 'String' not assignable to 'int'
}

This code is equivalent (the only difference is that the local variable tValue has been inlined), so it should be rejected too. It is correctly rejected by the CFE, but it is accepted by the analyzer:

int test<T extends int Function(int)>(T Function() createT) {
  return createT()('');
}

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions