Report StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS for dynamic and type parmaeters.

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

Bug: https://github.com/dart-lang/sdk/issues/28813
Change-Id: Iae43c0bb913bfd06fa09ddeacd6fdb8f81eccf9a
Reviewed-on: https://dart-review.googlesource.com/71423
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2018-08-26 03:42:31 +00:00
committed by commit-bot@chromium.org
parent 5e4e6037a9
commit 04e2ada09b
5 changed files with 29 additions and 50 deletions
+3 -34
View File
@@ -8179,51 +8179,20 @@ class TypeNameResolver {
}
DartType type = null;
if (element is ClassElement) {
_setElement(typeName, element);
type = element.type;
// In non-strong mode `FutureOr<T>` is treated as `dynamic`
if (!typeSystem.isStrong && type.isDartAsyncFutureOr) {
type = dynamicType;
_setElement(typeName, type.element);
typeName.staticType = type;
node.type = type;
if (argumentList != null) {
NodeList<TypeAnnotation> arguments = argumentList.arguments;
if (arguments.length != 1) {
reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node,
[typeName.name, 1, arguments.length]);
}
}
return;
}
} else if (element == DynamicElementImpl.instance) {
_setElement(typeName, element);
} else if (element is TypeDefiningElement &&
element.kind == ElementKind.DYNAMIC) {
// if (argumentList != null) {
// // Type parameters cannot have type arguments.
// // TODO(mfairhurst) Report this error.
// resolver.reportError(ResolverErrorCode.?, keyType);
// }
_setElement(typeName, element);
typeName.staticType = element.type;
node.type = element.type;
return;
type = DynamicTypeImpl.instance;
} else if (element is FunctionTypeAliasElement) {
_setElement(typeName, element);
type = element.type;
} else if (element is TypeParameterElement) {
_setElement(typeName, element);
type = element.type;
// if (argumentList != null) {
// // Type parameters cannot have type arguments.
// // TODO(brianwilkerson) Report this error.
// // resolver.reportError(ResolverErrorCode.?, keyType);
// }
} else if (element is MultiplyDefinedElement) {
List<Element> elements = element.conflictingElements;
type = _getTypeWhenMultiplyDefined(elements);
if (type != null) {
node.type = type;
}
} else {
// The name does not represent a type.
RedirectingConstructorKind redirectingConstructorKind;
@@ -292,6 +292,12 @@ class StaticTypeWarningCodeTest_Kernel
await super.test_undefinedSuperMethod();
}
@override
@failingTest
test_wrongNumberOfTypeArguments_typeParameter() async {
await super.test_wrongNumberOfTypeArguments_typeParameter();
}
@override
@failingTest
test_yield_async_to_basic_type() async {
@@ -2170,6 +2170,18 @@ class B extends A {
]);
}
test_wrongNumberOfTypeArguments_class_tooFew() async {
await assertErrorsInCode(r'''
class A<E, F> {}
A<A> a = null;''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
test_wrongNumberOfTypeArguments_class_tooMany() async {
await assertErrorsInCode(r'''
class A<E> {}
A<A, A> a = null;''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
test_wrongNumberOfTypeArguments_classAlias() async {
await assertErrorsInCode(r'''
class A {}
@@ -2178,16 +2190,18 @@ class B<F extends num> = A<F> with M;''',
[StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
test_wrongNumberOfTypeArguments_tooFew() async {
test_wrongNumberOfTypeArguments_dynamic() async {
await assertErrorsInCode(r'''
class A<E, F> {}
A<A> a = null;''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
dynamic<int> v;
''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
test_wrongNumberOfTypeArguments_tooMany() async {
test_wrongNumberOfTypeArguments_typeParameter() async {
await assertErrorsInCode(r'''
class A<E> {}
A<A, A> a = null;''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
class C<T> {
T<int> f;
}
''', [StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
}
test_wrongNumberOfTypeArguments_typeTest_tooFew() async {
@@ -404,7 +404,6 @@ accessor_conflict_import_prefixed_test: CompileTimeError # Issue 25626
accessor_conflict_import_test: CompileTimeError # Issue 25626
additional_interface_adds_optional_args_test: CompileTimeError # Issue #30568
built_in_identifier_prefix_test: CompileTimeError
built_in_identifier_type_annotation_test/dynamic-gen: MissingCompileTimeError # Issue 28813
cascaded_forwarding_stubs_test: CompileTimeError
check_member_static_test/01: CompileTimeError
config_import_corelib_test: CompileTimeError
@@ -444,10 +443,6 @@ index_assign_operator_infer_return_type_test: StaticWarning
initializing_formal_final_test: MissingCompileTimeError
interceptor6_test: CompileTimeError
interface_test/00: MissingCompileTimeError
invalid_type_argument_count_test/01: MissingCompileTimeError
invalid_type_argument_count_test/02: MissingCompileTimeError
invalid_type_argument_count_test/03: MissingCompileTimeError
invalid_type_argument_count_test/04: MissingCompileTimeError
issue13673_test: StaticWarning # Issue 31925
issue31596_implement_covariant_test: CompileTimeError
issue31596_override_test/01: CompileTimeError
@@ -26,7 +26,6 @@ bug32372_test: RuntimeError
built_in_identifier_prefix_test: CompileTimeError
built_in_identifier_type_annotation_test/dynamic-funarg: RuntimeError # Issue 28816
built_in_identifier_type_annotation_test/dynamic-funret: RuntimeError # Issue 28816
built_in_identifier_type_annotation_test/dynamic-gen: MissingCompileTimeError # Issue 28816
built_in_identifier_type_annotation_test/dynamic-list: RuntimeError # Issue 28816
cascaded_forwarding_stubs_generic_test: RuntimeError
cascaded_forwarding_stubs_test: CompileTimeError
@@ -84,10 +83,6 @@ instantiate_tearoff_after_contravariance_check_test: RuntimeError
instantiate_tearoff_of_call_test: RuntimeError
interface_test/00: MissingCompileTimeError
internal_library_test/01: MissingCompileTimeError # Issue 29920
invalid_type_argument_count_test/01: MissingCompileTimeError
invalid_type_argument_count_test/02: MissingCompileTimeError
invalid_type_argument_count_test/03: MissingCompileTimeError
invalid_type_argument_count_test/04: MissingCompileTimeError
issue31596_implement_covariant_test: CompileTimeError
issue31596_override_test/01: CompileTimeError
issue31596_override_test/02: CompileTimeError