mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Issue 50588. Test that EQUAL_KEYS_IN_MAP_PATTERN is reported for double(s).
Bug: https://github.com/dart-lang/sdk/issues/50588 Change-Id: I952d0ec59045c68f63a5f028083cf17c1b633f3f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286522 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
eb5c027d26
commit
3e62dba022
|
@ -15,7 +15,29 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class EqualKeysInMapPatternTest extends PubPackageResolutionTest {
|
||||
test_identical_primitiveEqual_identifier() async {
|
||||
test_identical_double() async {
|
||||
await assertErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {3.14: 1, 3.14: 2}) {}
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.EQUAL_KEYS_IN_MAP_PATTERN, 35, 4,
|
||||
contextMessages: [message('/home/test/lib/test.dart', 26, 4)]),
|
||||
]);
|
||||
}
|
||||
|
||||
test_identical_int() async {
|
||||
await assertErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {0: 1, 0: 2}) {}
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.EQUAL_KEYS_IN_MAP_PATTERN, 32, 1,
|
||||
contextMessages: [message('/home/test/lib/test.dart', 26, 1)]),
|
||||
]);
|
||||
}
|
||||
|
||||
test_identical_int_viaIdentifier() async {
|
||||
await assertErrorsInCode('''
|
||||
const a = 0;
|
||||
const b = 0;
|
||||
|
@ -29,18 +51,23 @@ void f(x) {
|
|||
]);
|
||||
}
|
||||
|
||||
test_identical_primitiveEqual_integerLiteral() async {
|
||||
await assertErrorsInCode('''
|
||||
test_notIdentical_double() async {
|
||||
await assertNoErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {0: 1, 0: 2}) {}
|
||||
if (x case {3.14: 1, 2.71: 2}) {}
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.EQUAL_KEYS_IN_MAP_PATTERN, 32, 1,
|
||||
contextMessages: [message('/home/test/lib/test.dart', 26, 1)]),
|
||||
]);
|
||||
''');
|
||||
}
|
||||
|
||||
test_notIdentical_notPrimitiveEqual_alwaysFalse() async {
|
||||
test_notIdentical_int() async {
|
||||
await assertNoErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {0: 1, 2: 3}) {}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_notIdentical_userClass() async {
|
||||
await assertNoErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {const A(0): 1, const A(2): 3}) {}
|
||||
|
@ -54,32 +81,23 @@ class A {
|
|||
''');
|
||||
}
|
||||
|
||||
test_notIdentical_notPrimitiveEqual_alwaysTrue() async {
|
||||
test_recordType_notPrimitiveEqual_named() async {
|
||||
await assertNoErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {const A(0): 1, const A(2): 3}) {}
|
||||
if (x case {(a: const A()): 1, (a: const A()): 2}) {}
|
||||
}
|
||||
|
||||
class A {
|
||||
final int field;
|
||||
const A(this.field);
|
||||
const A();
|
||||
bool operator ==(other) => true;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_notIdentical_primitiveEqual_integerLiteral() async {
|
||||
test_recordType_notPrimitiveEqual_positional() async {
|
||||
await assertNoErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {0: 1, 2: 3}) {}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_recordType_notPrimitiveEqual_named() async {
|
||||
await assertNoErrorsInCode('''
|
||||
void f(x) {
|
||||
if (x case {(a: const A()): 1, (a: const A()): 2}) {}
|
||||
if (x case {(0, const A()): 1, (0, const A()): 2}) {}
|
||||
}
|
||||
|
||||
class A {
|
||||
|
|
Loading…
Reference in a new issue