Skip to content

Analyzer doesn't detect compile-time error for mismatched types in constant containers #35748

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

Closed
stereotype441 opened this issue Jan 24, 2019 · 1 comment
Labels
analyzer-constants dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec legacy-area-analyzer Use area-devexp instead. 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

@stereotype441
Copy link
Member

Consider the following code (assuming --enable-experiment=set-literals):

const Object o = const Object();
main() {
  const a = <int>[o];
  const b = <int>{o};
  const c = <int, int>{o: 1};
  const d = <int, int>{1: o};
}

From a static error perspective, the constant declarations of a, b, c, and d are all valid, because Object is assignable to int. However, constant evaluation should report an error, because the type of the value of o is Object, and it is unsound to store a value of type Object in a list, set, or map where an int is expected.

The VM and dart2js report the correct error. The analyzer and DDC don't report any error at all.

@stereotype441 stereotype441 added legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 24, 2019
@srawlins srawlins added analyzer-constants dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec labels Jun 17, 2020
@srawlins
Copy link
Member

The analyzer now reports four errors:

error • The element type 'Object' can't be assigned to the list type 'int'. • a.dart:3:19 • list_element_type_not_assignable
error • The element type 'Object' can't be assigned to the set type 'int'. • a.dart:4:19 • set_element_type_not_assignable
error • The element type 'Object' can't be assigned to the map key type 'int'. • a.dart:5:24 • map_key_type_not_assignable
error • The element type 'Object' can't be assigned to the map value type 'int'. • a.dart:6:27 • map_value_type_not_assignable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-constants dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec legacy-area-analyzer Use area-devexp instead. 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

2 participants