Skip to content

Difference in map/set collection inference between analyzer and CFE #60367

@lrhn

Description

@lrhn

Example code:

int foo(bool something) =>
   {if (something) ...throw "Badness" else 1: 2}.length;

The CFE accepts the code as a map literal, and either throws or returns 1.

The analyzer reports:

This literal must be either a map or a set, but the elements don't have enough information for type inference to work.

The specification should end up in the case:

  • If leaf elements has at least one mapEntry and no expressionElement elements, then e is a map literal with unknown static type. The static type will be filled in by type inference, defined below.

In those steps, the context type, S, is empty, ?, and there are no type arguments. There is precisely one leaf element, 1: 2, and the ... throw "Badness" spread element won't be looked at until we reach type inference.

Metadata

Metadata

Labels

P2A bug or feature request we're likely to work onarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.dart-model-analyzer-specIssues with the analyzer's implementation of the language specmodel-discrepancyDiscrepancies between analyzer and cfetype-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