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

Potentially constant expressions not properly handled in string interpolations #19558

Closed
stereotype441 opened this issue Jun 19, 2014 · 2 comments
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

Comments

@stereotype441
Copy link
Member

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.

@iposva-google
Copy link
Contributor

Set owner to @mhausner.
Added Accepted label.

@DartBot
Copy link

DartBot commented Jun 19, 2014

This comment was originally written by @mhausner


Yes. Another incarnation of issue #392. When we compile the const Foo constructor, we don't know whether the call site will pass an actual parameter that makes "($x)" a compile-time const.


Added Duplicate label.
Marked as being merged into #392.

This issue was closed.
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. closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

4 participants