Skip to content

VM doesn't recognize top-level function as const in all cases. #27164

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
lrhn opened this issue Aug 26, 2016 · 2 comments
Closed

VM doesn't recognize top-level function as const in all cases. #27164

lrhn opened this issue Aug 26, 2016 · 2 comments
Assignees
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

@lrhn
Copy link
Member

lrhn commented Aug 26, 2016

Example:

void main() {
  print(const Echo().echo("test"));
}


[12:08:17]lrn@lrn:~/dart/co/sdk/dev (reapply-fix-remove-resource)
typedef String EchoType(String arg);

const EchoType cecho = simpleEcho;

class Echo {
  final EchoType echo;
  const Echo() : echo = simpleEcho;
  const Echo.verbose() : echo = verboseEcho;
}

String simpleEcho(String arg) => arg;

String verboseEcho(String arg) => "arg: $arg";

void main() {
//  print(cecho("c"));
  print(const Echo().echo("test"));
}

This program fails with the error:

'file:///.../echo.dart': error: line 21 pos 21: Invalid const object field: Closure: (String) => String from Function 'simpleEcho': static.

  print(const Echo().echo("test"));
                    ^

It fails to recognize that simpleEcho is a compile-time constant in initializer list of Echo().

However, if the commented out line is enabled, the simpleEcho function is recognized as constant, even in the following line.

The simpleEcho function is a compile-time function in all cases.

@lrhn lrhn added 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) labels Aug 26, 2016
mhausner added a commit that referenced this issue Sep 1, 2016
In const constructors, field initializer values that are known
to be compile-time constants should be evaluated and canonicalized
at compile time.

BUG=#27164
[email protected]

Review URL: https://codereview.chromium.org/2300113002 .
@mhausner
Copy link
Contributor

mhausner commented Sep 1, 2016

Fixed in c15bac4

@mhausner mhausner closed this as completed Sep 1, 2016
@mhausner
Copy link
Contributor

mhausner commented Sep 1, 2016

FWIW, this was another manifestation of the imperfect implementation of "potentially const values", issue #392. This fix makes it a bit less imperfect :)

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

2 participants