Tests for invalid Map literal type arguments resolution.

R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I4e1e78b9c5497b1399a8a5ca3f600cdbbe86cf23
Reviewed-on: https://dart-review.googlesource.com/65029
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2018-07-16 15:59:45 +00:00 committed by commit-bot@chromium.org
parent c9ba6a9709
commit ce682638d9
6 changed files with 66 additions and 29 deletions

View file

@ -41,20 +41,6 @@ class StaticTypeWarningCodeTest_Kernel
await super.test_assert_message_suppresses_type_promotion();
}
@override
@failingTest
test_expectedTwoMapTypeArguments_one() async {
// Bad state: Found 2 argument types for 1 type arguments
await super.test_expectedTwoMapTypeArguments_one();
}
@override
@failingTest
test_expectedTwoMapTypeArguments_three() async {
// Bad state: Found 2 argument types for 3 type arguments
await super.test_expectedTwoMapTypeArguments_three();
}
@override
@failingTest
test_illegalAsyncGeneratorReturnType_function_nonStream() async {

View file

@ -44,6 +44,8 @@ class AnalysisDriverResolutionTest extends BaseAnalysisDriverTest {
FindNode findNode;
FindElement findElement;
ClassElement get boolElement => typeProvider.boolType.element;
ClassElement get doubleElement => typeProvider.doubleType.element;
InterfaceType get doubleType => typeProvider.doubleType;
@ -4724,6 +4726,48 @@ void main() {
}
}
test_mapLiteral_1() async {
addTestFile(r'''
main() {
var v = <int>{};
}
''');
await resolveTestFile();
expect(result.errors, isNotEmpty);
var literal = findNode.mapLiteral('<int>{}');
assertType(literal, 'Map<dynamic, dynamic>');
var intRef = findNode.simple('int>{}');
assertElement(intRef, intElement);
assertType(intRef, 'int');
}
test_mapLiteral_3() async {
addTestFile(r'''
main() {
var v = <bool, int, double>{};
}
''');
await resolveTestFile();
expect(result.errors, isNotEmpty);
var literal = findNode.mapLiteral('<bool, int, double>{}');
assertType(literal, 'Map<dynamic, dynamic>');
var boolRef = findNode.simple('bool, ');
assertElement(boolRef, boolElement);
assertType(boolRef, 'bool');
var intRef = findNode.simple('int, ');
assertElement(intRef, intElement);
assertType(intRef, 'int');
var doubleRef = findNode.simple('double>');
assertElement(doubleRef, doubleElement);
assertType(doubleRef, 'double');
}
test_method_namedParameters() async {
addTestFile(r'''
class C {
@ -8558,6 +8602,10 @@ class FindNode {
return _node(search).getAncestor((n) => n is ListLiteral);
}
MapLiteral mapLiteral(String search) {
return _node(search).getAncestor((n) => n is MapLiteral);
}
MethodInvocation methodInvocation(String search) {
return _node(search).getAncestor((n) => n is MethodInvocation);
}

View file

@ -4296,16 +4296,6 @@ const MessageCode messageListLiteralTooManyTypeArguments = const MessageCode(
severity: Severity.errorLegacyWarning,
message: r"""List literal requires exactly one type argument.""");
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeListLiteralTypeArgumentMismatch =
messageListLiteralTypeArgumentMismatch;
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageListLiteralTypeArgumentMismatch = const MessageCode(
"ListLiteralTypeArgumentMismatch",
severity: Severity.errorLegacyWarning,
message: r"""Map literal requires two type arguments.""");
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<
Message Function(Uri uri_)> templateLoadLibraryHidesMember = const Template<
@ -4389,6 +4379,18 @@ Message _withArgumentsLocalDefinitionHidesImport(String name, Uri uri_) {
arguments: {'name': name, 'uri': uri_});
}
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeMapLiteralTypeArgumentMismatch =
messageMapLiteralTypeArgumentMismatch;
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageMapLiteralTypeArgumentMismatch = const MessageCode(
"MapLiteralTypeArgumentMismatch",
analyzerCode: "EXPECTED_TWO_MAP_TYPE_ARGUMENTS",
dart2jsCode: "*fatal*",
severity: Severity.errorLegacyWarning,
message: r"""Map literal requires exactly two type arguments.""");
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeMemberWithSameNameAsClass =
messageMemberWithSameNameAsClass;

View file

@ -2128,7 +2128,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
if (typeArguments != null) {
if (forest.getTypeCount(typeArguments) != 2) {
addProblem(
fasta.messageListLiteralTypeArgumentMismatch,
fasta.messageMapLiteralTypeArgumentMismatch,
offsetForToken(leftBrace),
lengthOfSpan(leftBrace, leftBrace.endGroup));
} else {

View file

@ -215,9 +215,8 @@ InvalidVoid/script2: Fail
LibraryDirectiveNotFirst/script2: Fail
LibraryDirectiveNotFirst/script3: Fail
ListLiteralTooManyTypeArguments/example: Fail
ListLiteralTypeArgumentMismatch/analyzerCode: Fail
ListLiteralTypeArgumentMismatch/example: Fail
LoadLibraryTakesNoArguments/example: Fail
MapLiteralTypeArgumentMismatch/example: Fail
MemberWithSameNameAsClass/analyzerCode: Fail
MemberWithSameNameAsClass/example: Fail
MetadataTypeArguments/analyzerCode: Fail

View file

@ -1223,9 +1223,11 @@ ListLiteralTooManyTypeArguments:
analyzerCode: EXPECTED_ONE_LIST_TYPE_ARGUMENTS
dart2jsCode: "*fatal*"
ListLiteralTypeArgumentMismatch:
template: "Map literal requires two type arguments."
MapLiteralTypeArgumentMismatch:
template: "Map literal requires exactly two type arguments."
severity: ERROR_LEGACY_WARNING
analyzerCode: EXPECTED_TWO_MAP_TYPE_ARGUMENTS
dart2jsCode: "*fatal*"
LoadLibraryTakesNoArguments:
template: "'loadLibrary' takes no arguments."