Potentially constant expressions not properly handled in string interpolations #19558
Labels
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
closed-duplicate
Closed in favor of an existing report
The following code:
class Foo {
final String s;
const Foo(String x) : s = "($x)";
}
main() {
const Foo f = const Foo('bar');
print(f.s);
}
is rejected by the VM with the error message "initializer expression must be compile time constant."
However, based on my understanding of the language spec, this should be allowed. The spec says:
(in section "Constant Constructors"): "Any expression that appears within the initializer list of a constant constructor must be a potentially constant expression, or a compile-time error occurs. A potentially constant expression is an expression e that would be a valid constant expression if all formal parameters of e’s immediately enclosing constant constructor were treated as compile-time constants that were guaranteed to evaluate to an integer, boolean or string value as required by their immediately enclosing superexpression."
(in section "Constants"): "A constant expression is one of the following: ... A literal string where any interpolated expression is a compile-time constant that evaluates to a numeric, string or boolean value or to null."
Analyzer and dart2js treat the above code as valid.
The text was updated successfully, but these errors were encountered: