mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:14:36 +00:00
Set or map literals can be ambiguous in invalid code
Change-Id: Ic17f5b80836bdf1891065af97adf5e9a5e021995 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105021 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
94968f9bae
commit
788dcf681e
|
@ -1184,11 +1184,12 @@ class CodeChecker extends RecursiveAstVisitor {
|
|||
if (expr.isMap) {
|
||||
_recordMessage(
|
||||
expr, StrongModeCode.INVALID_CAST_LITERAL_MAP, [from, to]);
|
||||
} else {
|
||||
// Ambiguity should be resolved by now
|
||||
assert(expr.isSet);
|
||||
} else if (expr.isSet) {
|
||||
_recordMessage(
|
||||
expr, StrongModeCode.INVALID_CAST_LITERAL_SET, [from, to]);
|
||||
} else {
|
||||
// This should only happen when the code is invalid, in which case
|
||||
// the error should have been reported elsewhere.
|
||||
}
|
||||
} else {
|
||||
_recordMessage(
|
||||
|
|
|
@ -29,6 +29,15 @@ var c = {...set, ...map};
|
|||
|
||||
@reflectiveTest
|
||||
class AmbiguousSetOrMapLiteralEitherTest extends DriverResolutionTest {
|
||||
test_invalidPrefixOperator() async {
|
||||
// Guard against an exception being thrown.
|
||||
await assertErrorsInCode('''
|
||||
union(a, b) => !{...a, ...b};
|
||||
''', [
|
||||
error(CompileTimeErrorCode.AMBIGUOUS_SET_OR_MAP_LITERAL_EITHER, 16, 12),
|
||||
]);
|
||||
}
|
||||
|
||||
test_setAndMap() async {
|
||||
assertErrorsInCode('''
|
||||
var map;
|
||||
|
|
Loading…
Reference in a new issue