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

It is a compile-time error if actual parameters to const constructor result in invalid constant expressions #34192

Closed
askeksa-google opened this issue Aug 20, 2018 · 4 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-missing-error front-end-requires-constant-evaluation Issue that can't be solved without evaluating compile-time constants

Comments

@askeksa-google
Copy link

From co19_2/Language/Classes/Constructors/Constant_Constructors/invalid_constant_initializer_t02:

class A {
  final x;
  const A(var p) : x = p + 42;
}

class IntPair {
  const IntPair(this.x, this.y);
  final int x;
  final int y;
  operator +(v) => new IntPair(x+v, y+v);
}


main() {
  try {
    var a = const A(const IntPair(1,2)); // parameter does not evaluate to int/bool/String, despite implementing the plus operator
  } catch (x) {}
}

The spec says (in 10.6.3):
"When invoked from a constant object expression, a constant constructor must throw an exception if any of its actual parameters is a value that would prevent one of the potentially constant expressions within it from being a valid compile-time constant."

Here, must throw an exception should be interpreted as should be treated as if it would have thrown an exception, i.e. it is a compile-time error.

@askeksa-google askeksa-google added area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-missing-error front-end-requires-constant-evaluation Issue that can't be solved without evaluating compile-time constants labels Aug 20, 2018
@eernstg
Copy link
Member

eernstg commented Aug 20, 2018

With this CL, landed as 1a2532c, the situation should be less ambiguous.

@johnniwinther
Copy link
Member

FYI: this error is reported by dart2js.

@sigmundch
Copy link
Member

(reopened because we temporarily disabled the constant-update-2018 experiment)

@sigmundch sigmundch reopened this Apr 16, 2019
@askeksa-google
Copy link
Author

Closing because there is no more work to do on this except flipping the flag. This will give us a better overview of remaining issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-missing-error front-end-requires-constant-evaluation Issue that can't be solved without evaluating compile-time constants
Projects
None yet
Development

No branches or pull requests

4 participants