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

Analyzer: Doesn't catch "not a compile-time constant" #31090

Open
matanlurey opened this Issue Oct 12, 2017 · 1 comment

Comments

Projects
None yet
5 participants
@matanlurey
Contributor

matanlurey commented Oct 12, 2017

This seems invalid in at least Dart2JS and DDC:

void main() {
  const ClassProvider<Iterable, List>();
}

class ClassProvider<T, C extends T> extends SlowProvider<T> {
  const ClassProvider() : super._(T, useClass: C);
}

class SlowProvider<T> {
  final Type a;
  
  const SlowProvider._(this.a, {Type useClass});
}

... causes ...


HTML OUTPUT
CONSOLE
Error compiling to JavaScript:
main.dart:6:35:
Error: Not a compile-time constant.
  const ClassProvider() : super._(T, useClass: C);
                                  ^
main.dart:6:48:
Error: Not a compile-time constant.
  const ClassProvider() : super._(T, useClass: C);
                                               ^
main.dart:6:35:
Error: Not a compile-time constant.
  const ClassProvider() : super._(T, useClass: C);
                                  ^
main.dart:6:48:
Error: Not a compile-time constant.
  const ClassProvider() : super._(T, useClass: C);
                                               ^
Error: Compilation failed.

But nothing is flagged in the analyzer.

@lrhn

This comment has been minimized.

Show comment
Hide comment
@lrhn

lrhn Oct 18, 2017

Member

The Dart 1 specification does not allow class type parameters as constant expressions inside a const constructor.
There is no practical reason not to allow it, but the specification doesn't mention it as a valid const expression, so it isn't.

Member

lrhn commented Oct 18, 2017

The Dart 1 specification does not allow class type parameters as constant expressions inside a const constructor.
There is no practical reason not to allow it, but the specification doesn't mention it as a valid const expression, so it isn't.

@lrhn lrhn added the type-bug label Oct 18, 2017

@bwilkerson bwilkerson added the p2-medium label Feb 2, 2018

@bwilkerson bwilkerson added this to the Dart2.1 milestone Sep 3, 2018

@bwilkerson bwilkerson modified the milestones: Dart2.1, PostDart2.1 Sep 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment