Skip to content

can't use subtraction to initialize int in const constructor #12367

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
DartBot opened this issue Aug 11, 2013 · 4 comments
Closed

can't use subtraction to initialize int in const constructor #12367

DartBot opened this issue Aug 11, 2013 · 4 comments
Assignees
Labels
legacy-area-analyzer Use area-devexp instead.
Milestone

Comments

@DartBot
Copy link

DartBot commented Aug 11, 2013

This issue was originally filed by [email protected]


This works:

class DigitSet {
  final int bits;
  const DigitSet.single(int digit) : bits = 1 << digit;
}

This doesn't:

class DigitSet {
  final int bits;
  const DigitSet.single(int digit) : bits = 1 << (digit - 1);
}

The Dart editor reports an error for the const constructor: "An expression of type int was expected".

If you remove "const" it also works.

The problem seems to be that the subtraction operator is declared to return a "num" and for some reason, Dart doesn't automatically downcast it to "int" when the constructor is marked "const".

@lrhn
Copy link
Member

lrhn commented Aug 12, 2013

Added Area-Analyzer, Accepted labels.

@bwilkerson
Copy link
Member

Added this to the M6 milestone.
Removed Priority-Unassigned label.
Added Priority-Medium label.

@bwilkerson
Copy link
Member

Set owner to @bwilkerson.
Added Started label.

@bwilkerson
Copy link
Member

https://codereview.chromium.org/23382010/ (bleeding edge revision 26539)


Added Fixed label.

This issue was closed.
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.
Projects
None yet
Development

No branches or pull requests

3 participants