Files
sdk/pkg/front_end/testcases/patterns/pattern_variable_const.dart.strong.modular.expect
T
Johnni Winther 734c01da41 [cfe][PrimaryConstructors] Handle assignment to primary constructor parameter
This reports an error on assignment to primary constructor parameters in field initializers and initializer lists.

The change includes a rewrite of the handle of variable lookup and use that fixes and existing problem in pattern assignment, where it was until now possible to assign to const and final variable in some cases.

Part of #61700

Change-Id: Icfe566fd03b805e8fc21c4b373dbb8ab3dab4b7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484141
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-03-02 03:22:54 -08:00

26 lines
664 B
Plaintext

library;
//
// Problems in library:
//
// pkg/front_end/testcases/patterns/pattern_variable_const.dart:7:7: Error: Can't assign to the const variable 'j'.
// (_, j) = r;
// ^
//
import self as self;
import "dart:core" as core;
static method method((core::int, core::int) r) → dynamic {
const core::int j = #C1;
{
final synthesized(core::int, core::int) #0#0 = r;
if(!invalid-expression "pkg/front_end/testcases/patterns/pattern_variable_const.dart:7:7: Error: Can't assign to the const variable 'j'.
(_, j) = r;
^")
throw{for-error-handling} new core::StateError::•("Pattern matching error");
}
}
constants {
#C1 = 0
}