Files
sdk/pkg/front_end/testcases/patterns/pattern_assignment_final.dart
Paul Berry 0f11c4ed5a front_end: make use of TypeAnalyzer.analyzeConstantPattern.
This will allow the front end to take advantage of flow analysis
implied by a constant pattern (e.g. `case null` cause the scrutinee to
be promoted in later cases).

Fixes #51206.

Change-Id: Ic8516abb4e051ffca0d4e7698339282812020cae
Bug: https://github.com/dart-lang/sdk/issues/51206
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281261
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2023-02-09 18:41:01 +00:00

40 lines
1.1 KiB
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class Class {
dynamic field1;
dynamic field2;
}
method(x, y, z) {
final initializedFinal = 5;
late final initializedLateFinal = 5;
final definitelyUnassignedFinal;
late final int definitelyUnassignedLateFinal;
final definitelyAssignedFinal;
late final definitelyAssignedLateFinal;
final int notDefinitelyAssignedFinal;
late final int notDefinitelyAssignedLateFinal;
if (x == 5) {
notDefinitelyAssignedFinal = 5;
notDefinitelyAssignedLateFinal = 15;
}
definitelyAssignedFinal = 10;
definitelyAssignedLateFinal = 20;
(initializedFinal, // Error
initializedLateFinal, // Error
definitelyUnassignedFinal) = x; // Ok
[definitelyUnassignedLateFinal, // Ok
definitelyAssignedFinal] = y; // Error
Class(field1: definitelyAssignedLateFinal, // Error
field2: [[notDefinitelyAssignedFinal, _], // Error
[_, notDefinitelyAssignedLateFinal]]) = z; // Ok
}