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
dart2js: does not reports error when using argument to const constructor in const constructor in initializer list #12690
Comments
The VM is correct. The specification is explicit about this: The argument to a const constructor invocation must be a compile time constant. It is not enough that it is a potential compile-time constant. The bug here is that dart2js do not report an error. The analyzer may want to check too. Shorter example: class Other { Removed Area-VM label. |
Adding Lars and Gilad since this is really a question about the language semantics. Clearly, the level parameter is always a compile-time constant if the C constructor is invoked as a const constructor (as in 'const C(42)') but not necessarily if C is invoked using 'new C(x)'. At some point, we (at least) discussed automatically turning the 'const Other(level)' invocation into 'new Other(level)' when C is invoked as 'new C(x)'. |
This comment was originally written by @mhausner Please don't make this more complicated than it already is. Also consider the complication that arises if the argument is used in an expression. class Other { Here level+1 is a compile-time constant only if level is a number, but not if it's some other type. |
I agree with comment #3. We should not be fiddling with these rules at this point. |
IIRC, we decided to drop the "turn const Other into new Other" approach to keep things simple. |
Added this to the M7 milestone. |
Removed Priority-Unassigned label. |
Marked this as blocking #5519. |
Set owner to @karlklose. |
Changed the title to: "dart2js: does not reports error when using argument to const constructor in const constructor in initializer list". |
Removed this from the 1.6 milestone. |
Removed Oldschool-Milestone-1.6 label. |
class Const1 {
final int arg;
final Const2 c2;
const Const1({int arg})
: arg = arg,
c2 = const Const2(arg: arg);
}
class Const2 {
final int arg;
const Const2({int this.arg});
}
void main() {
const v = const Const1(arg: 1);
}
reports
const.dart': Error: line 9 pos 31: expression must be a compile-time constant
c2 = const Const2(arg: arg);
^
The text was updated successfully, but these errors were encountered: