Skip to content

Cannot use const ctor on a Class with a generic field - error in checked mode #22431

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
kevmoo opened this issue Feb 15, 2015 · 5 comments
Closed
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

@kevmoo
Copy link
Member

kevmoo commented Feb 15, 2015

class Foo {
  final List<int> values;

  const Foo(this.values);
}

const _foo = const Foo(const <int>[1,2,3]);

This fails in checked mode because "const <int>[1,2,3]" has a rarified type of "List<Object>", not "List<int>"

@gbracha
Copy link
Contributor

gbracha commented Feb 17, 2015

That sounds like a bug. Is it VM or dart2js?

@kevmoo
Copy link
Member Author

kevmoo commented Feb 17, 2015

The error happened in the VM.

Are you saying the type of the List should be treated as a List<dynamic> instead of a List<Object> in the VM?

@gbracha
Copy link
Contributor

gbracha commented Feb 17, 2015

I'm saying that const<int>[1, 2, 3] should have reified type List<int> as you expected when you wrote the code. If you had written const [1, 2, 3] it would be List<dynamic>. Only if you wrote <Object>[1, 2, 3] would it be List<Object>.

Assigning to the VM.


Removed Area-Language label.
Added Area-VM label.

@lrhn
Copy link
Member

lrhn commented May 19, 2015

Removed Type-Enhancement label.
Added Type-Defect label.

@kevmoo kevmoo added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels May 19, 2015
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Mar 1, 2016
@mhausner
Copy link
Contributor

The code does not fail on the VM, including checked mode.

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

4 participants