Files
sdk/pkg/front_end/testcases/patterns/shared_errors.dart
T
Johnni Winther ed7124884a [cfe] Implement shared error reporting
Change-Id: Ief8d557d0e6553fa79e7281172caccb00dfc5cfb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280086
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-01-30 18:42:38 +00:00

76 lines
1.5 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 {
int get field => 42;
bool operator >=(Class cls) => true;
Class operator >(int i) => new Class();
}
argumentTypeNotAssignable(Class cls) {
switch (cls) {
case >= 0: // Error
print(0);
}
}
relationalPatternOperatorReturnTypeNotAssignableToBool(Class cls) {
switch (cls) {
case > 0: // Error
print(0);
}
}
patternTypeMismatchInIrrefutableContext(List<String> list) {
var <int>[a] = list; // Error
}
duplicateAssignmentPatternVariable(List<String> list) {
String a = '';
[a, a] = list; // Error
}
duplicateRecordPatternField(o) {
switch (o) {
case (field: 1, field: 2): // Error
case Class(field: 1, field: 2): // Error
print(0);
}
}
duplicateRestPattern(o) {
switch (o) {
case [..., ...]: // Error
case {..., ...}: // Error
}
}
matchedTypeIsStrictlyNonNullable(List<int> list) {
if (list case [var a!, var b?]) { // Warnings
print(0);
}
}
nonBooleanCondition(int i) {
if (i case 0 when i) { // Error
print(0);
}
}
refutablePatternInIrrefutableContext(int? x) {
var (a?) = x; // Error
}
restPatternNotLastInMap(o) {
if (o case {..., 5: 3}) { // Error
print(0);
}
}
restPatternWithSubPatternInMap(o) {
if (o case {5: 3, ...var a}) { // Error
print(0);
}
}