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

No error if a non-constant is used in a constant constructor initializer list #59804

Open
sgrekhov opened this issue Dec 25, 2024 · 0 comments
Open
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

The code below produces an error in the analyzer but works in VM.

class A {
  int id;
  A(this.id);
  static A answer = A(42);
}

class C {
  final A a;
  const C(this.a);
  const C.fromAnswer() : a = A.answer; // Analyzer: Invalid constant value.
}

main() {
  print(C.fromAnswer().a.id); // prints 42
}

There should be an error in VM as well.

Dart SDK version: 3.7.0-274.0.dev (dev) (Thu Dec 19 20:06:50 2024 -0800) on "windows_x64"

@sgrekhov sgrekhov added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Dec 25, 2024
@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants