Skip to content

Incorrect constant evaluation of lists declared in another file #35230

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 Nov 20, 2018 · 2 comments
Closed

Incorrect constant evaluation of lists declared in another file #35230

stereotype441 opened this issue Nov 20, 2018 · 2 comments
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@stereotype441
Copy link
Member

Consider the following code:

lib.dart:

const x = const <String>['a'];

main.dart:

import 'lib.dart';
const y = const <String>['b'];
int f(v) {
  switch(v) {
    case x:
      return 0;
    case y:
      return 1;
    default:
      return 2;
  }
}

If the analysis driver visits main.dart first, then it evaluates the constant x as having the value <dynamic>['a'], and the constant y as having the value <String>['b']. This is incorrect--both lists should have type argument <String>. As a result, the error INCONSISTENT_CASE_EXPRESSION_TYPES is reportend.

Note that the type that is incorrect is the type of the constant value, not the static type of the constant declaration. Replacing const x = ... with const List<String>x = ... in the code above is not sufficient to work around the bug.

It's also possible to get inconsistencies between two constants declared in the same file, if one of the constants is referred to by another file, and the analysis driver visits that other file first.

@stereotype441 stereotype441 added P1 A high priority bug; for example, a single project is unusable or has many test failures legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 20, 2018
@stereotype441 stereotype441 self-assigned this Nov 20, 2018
@stereotype441
Copy link
Member Author

I'm working on a fix

@bwilkerson
Copy link
Member

@keertip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants