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:
Brian Wilkerson 2019-06-05 16:30:12 +00:00 committed by commit-bot@chromium.org
parent 94968f9bae
commit 788dcf681e
2 changed files with 13 additions and 3 deletions

View file

@ -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(

View file

@ -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;