Files
sdk/pkg/front_end/testcases/patterns/exhaustiveness/object_pattern.dart
T
Johnni Winther 03700211b2 [_fe_analyzer_shared] Create pattern syntax for witnesses
This updates the toString on Witness to produce pattern code. The
created pattern is directly derived from the predicates of the
witness and there contain some needless precision, for instance
`[...[...]]` instead of `[...]`. It is the plan to address this in
a follow-up.

Change-Id: Ied7930f36b1e1818540b8c635b18ff92f28e113b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290720
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-03-23 16:25:41 +00:00

35 lines
783 B
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 A {
int field1;
num field2;
A(this.field1, this.field2);
}
exhaustiveDirect(A a) => switch (a) {
A() => 0,
};
exhaustiveWithWildcards(A a) => switch (a) {
A(field1: _, field2: _) => 0,
};
exhaustiveWithFields(A a) => switch (a) {
A(:var field1, :var field2) => 0,
};
exhaustiveWithTypedFields(A a) => switch (a) {
A(:int field1, :num field2) => 0,
};
nonExhaustiveFixedField(A a) => switch (a) {
A(field1: 5) => 0,
};
nonExhaustiveTypedField(A a) => switch (a) {
A(:int field2) => 0,
};