Skip to content

improve error messages on invalid constants #33438

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
sigmundch opened this issue Jun 13, 2018 · 4 comments
Closed

improve error messages on invalid constants #33438

sigmundch opened this issue Jun 13, 2018 · 4 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop P2 A bug or feature request we're likely to work on web-dart2js
Milestone

Comments

@sigmundch
Copy link
Member

We need to provide better error message when constants are invalid.

One scenario that especially needs more data is generic instantiation that are substituted by a type variable (since type variables can be used in a constant context).

Compare the error message you get from these 2 examples:

class A<T> {
  final List<T> f;
  A([this.f = const <T>[]]);
}

main() => print(new A<String>().f);
Error: Type variable 'T' can't be used as a constant expression #lib1::A::T.
Q generic<Q>() => null;

class A<T> {
  final T Function() f;
  A([this.f = generic]);
}

main() => print(new A<String>().f);
Error: Not a compile-time constant.
@zoechi
Copy link
Contributor

zoechi commented Jul 17, 2018

Similar to #33216 ?

@sigmundch
Copy link
Member Author

Very similar, but still a separate issue because #33216 tracks error reporting for constants in the vm. (most errors are reported by the front-end, but constants are not evaluated in the front-end, instead each backend (dart2js, vm) has it's own evaluation logic and error reporting)

@vsmenon
Copy link
Member

vsmenon commented Oct 1, 2018

Bump past 2.1?

@sigmundch sigmundch modified the milestones: Dart2.1, PostDart2.1 Oct 1, 2018
@aadilmaan aadilmaan modified the milestones: Future, D25 Release Jun 4, 2019
@vsmenon vsmenon added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop label Jul 20, 2019
@sigmundch
Copy link
Member Author

Since we flipped the constant-update-2018 flag, the CFE now does all constant evaluation and a reasonable error is given for the second case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop P2 A bug or feature request we're likely to work on web-dart2js
Projects
None yet
Development

No branches or pull requests

4 participants