Skip to content

[Records] Constant evaluation errors inside record literals #50132

Closed
@alexmarkov

Description

@alexmarkov

Part of #49713.

Test co19/LanguageFeatures/Records/canonicalization_A02_t01 fails because front-end doesn't treat const constructor parameters as potentially constant if they are used inside record literal:

class A {
  final (int, int) pair;
  const A(int x, int y) : pair = (x, y);
}

void main() {
  print(const A(1, 2));
}
foo.dart:3:34: Error: Constant evaluation error:
  const A(int x, int y) : pair = (x, y);
                                 ^
foo.dart:3:35: Context: The variable 'x' is not a constant, only constant expressions are allowed.
  const A(int x, int y) : pair = (x, y);
                                  ^

@johnniwinther

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions