Files
Johnni Winther 31e119e594 [cfe] Report error on empty map pattern
This reports the error on empty map pattern and moves the reporting
of rest patterns in map patterns to the shared analysis.

Change-Id: I317d0c42a3bc7534462b1b9781c1f6471746fc0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292860
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-04 09:36:38 +00:00

88 lines
1.6 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
}
}
emptyMapPattern(o) {
switch (o) {
case {}: // Error
}
}
singleRestPatternInMap(o) {
switch (o) {
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);
}
}