Skip to content
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

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

Open
lrhn opened this issue Mar 20, 2025 · 0 comments
Open

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

lrhn opened this issue Mar 20, 2025 · 0 comments
Assignees
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec model-discrepancy Discrepancies between analyzer and cfe P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Mar 20, 2025

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.

@lrhn lrhn added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Mar 20, 2025
@johnniwinther johnniwinther added model-discrepancy Discrepancies between analyzer and cfe P2 A bug or feature request we're likely to work on labels Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec model-discrepancy Discrepancies between analyzer and cfe P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants