Check whether type-arguments and type-parameters length match from the body builder.

Bug:
Change-Id: I395365393c9032ff179d675f42ca56b7981531e0
Reviewed-on: https://dart-review.googlesource.com/5620
Reviewed-by: Peter von der Ahé <ahe@google.com>
This commit is contained in:
Sigmund Cherem
2017-09-15 20:37:41 +00:00
parent 5923ff4900
commit 321a4ec048
10 changed files with 87 additions and 25 deletions
@@ -2909,6 +2909,28 @@ const MessageCode messageTypeAfterVar = const MessageCode("TypeAfterVar",
message: r"""Can't have both a type and 'var'.""",
tip: r"""Try removing 'var.'""");
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(String name, String string)>
templateTypeArgumentMismatch =
const Template<Message Function(String name, String string)>(
messageTemplate: r"""'#name' expects #string type arguments.""",
withArguments: _withArgumentsTypeArgumentMismatch);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Message Function(String name, String string)>
codeTypeArgumentMismatch =
const Code<Message Function(String name, String string)>(
"TypeArgumentMismatch",
templateTypeArgumentMismatch,
);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsTypeArgumentMismatch(String name, String string) {
return new Message(codeTypeArgumentMismatch,
message: """'$name' expects $string type arguments.""",
arguments: {'name': name, 'string': string});
}
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(String name)>
templateTypeArgumentsOnTypeVariable =
@@ -1016,6 +1016,13 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
charOffset);
}
@override
void warnTypeArgumentsMismatch(String name, int expected, int charOffset) {
warning(
fasta.templateTypeArgumentMismatch.withArguments(name, '${expected}'),
charOffset);
}
@override
Member lookupSuperMember(Name name, {bool isSetter: false}) {
Class superclass = classBuilder.cls.superclass;
@@ -37,6 +37,7 @@ import 'frontend_accessors.dart' show Accessor;
import 'kernel_builder.dart'
show
Builder,
FunctionTypeAliasBuilder,
KernelClassBuilder,
KernelInvalidTypeBuilder,
LibraryBuilder,
@@ -130,6 +131,8 @@ abstract class BuilderHelper {
void warnUnresolvedSuperSet(Name name, int charOffset);
void warnUnresolvedSuperMethod(Name name, int charOffset);
void warnTypeArgumentsMismatch(String name, int expected, int charOffset);
}
abstract class FastaAccessor implements Accessor {
@@ -1025,6 +1028,27 @@ class TypeDeclarationAccessor extends ReadOnlyAccessor {
DartType buildType(List<DartType> arguments,
{bool nonInstanceAccessIsError: false}) {
if (arguments != null) {
int expected = 0;
if (declaration is KernelClassBuilder) {
expected = declaration.target.typeParameters.length;
} else if (declaration is FunctionTypeAliasBuilder) {
expected = declaration.target.typeParameters.length;
} else {
return unhandled(
"${declaration.runtimeType}",
"TypeDeclarationAccessor.buildType",
offsetForToken(token),
helper.uri);
}
if (arguments.length != expected) {
helper.warnTypeArgumentsMismatch(
declaration.name, expected, offsetForToken(token));
// TODO(sigmund): include more details in InvalidType about why the type
// is invalid (see #29840).
return const InvalidType();
}
}
DartType type =
declaration.buildTypesWithBuiltArguments(helper.library, arguments);
if (type is TypeParameterType) {
+4
View File
@@ -541,6 +541,10 @@ ListLiteralTooManyTypeArguments:
ListLiteralTypeArgumentMismatch:
template: "Map literal requires two type arguments."
TypeArgumentMismatch:
# TODO(sigmund): #string should be a number instead.
template: "'#name' expects #string type arguments."
NotAType:
template: "'#name' isn't a type."
-1
View File
@@ -96,7 +96,6 @@ regress/issue_29944: Crash # Issue 29944.
regress/issue_29975: Fail # Issue 29975.
regress/issue_29976: RuntimeError
regress/issue_29977: Crash # Issue 29977.
regress/issue_29981: Crash # Issue 29981.
regress/issue_29982: RuntimeError
regress/issue_29983: Crash # Issue 29983.
regress/issue_29984: Crash # Issue 29984.
@@ -0,0 +1,13 @@
library;
import self as self;
import "dart:core" as core;
class C<T extends core::Object> extends core::Object {
field self::C<core::String> field = null;
default constructor •() → void
: super core::Object::•()
;
}
static method main() → dynamic {
core::print(new self::C::•<dynamic>());
}
@@ -0,0 +1,13 @@
library;
import self as self;
import "dart:core" as core;
class C<T extends core::Object> extends core::Object {
field self::C<core::String> field = null;
default constructor •() → void
: super core::Object::•()
;
}
static method main() → dynamic {
core::print(new self::C::•<dynamic>());
}
-1
View File
@@ -156,7 +156,6 @@ regress/issue_29944: Crash # Issue 29944.
regress/issue_29975: Fail # Issue 29975.
regress/issue_29976: RuntimeError # Issue 29976.
regress/issue_29977: Crash # Issue 29977.
regress/issue_29981: Crash # Issue 29981.
regress/issue_29982: RuntimeError # Issue 29982.
regress/issue_29983: Crash # Issue 29983.
regress/issue_29984: Crash # Issue 29984.
+4 -21
View File
@@ -647,7 +647,6 @@ for_variable_capture_test: RuntimeError
full_stacktrace1_test: RuntimeError
full_stacktrace2_test: RuntimeError
full_stacktrace3_test: RuntimeError
function_malformed_result_type_test: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
function_subtype_cast2_test: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in (local(Class.test#)) for j:closure_call(Class_test_closure.call).
function_subtype_cast3_test: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in (local(Class.test#local)) for j:closure_call(Class_test_closure.call).
function_subtype_closure0_test: Crash # NoSuchMethodError: The method 'hasSubclass' was called on null.
@@ -704,12 +703,8 @@ main_test/42: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Faile
main_test/43: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
main_test/44: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
main_test/45: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
malformed_test/01: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
malformed_test/02: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
malformed_test/03: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
malformed_test/04: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
malformed_test/06: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
malformed_test/none: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
malformed_test/06: CompileTimeError
malformed_test/none: Crash # Internal Error: Non-empty instruction stack
many_named_arguments_test: RuntimeError
map_literal4_test: RuntimeError
method_name_test: CompileTimeError
@@ -968,22 +963,13 @@ syncstar_less_than_test: RuntimeError
syncstar_yield_test/copyParameters: RuntimeError
syncstar_yield_test/none: RuntimeError
syncstar_yieldstar_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
syntax_test/02: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/03: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/27: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/28: Crash # type 'KernelConstructorBuilder' is not a subtype of type 'KernelProcedureBuilder' of 'method' where
syntax_test/29: Crash # type 'KernelConstructorBuilder' is not a subtype of type 'KernelProcedureBuilder' of 'method' where
syntax_test/30: Crash # type 'KernelConstructorBuilder' is not a subtype of type 'KernelProcedureBuilder' of 'method' where
syntax_test/31: Crash # type 'KernelConstructorBuilder' is not a subtype of type 'KernelProcedureBuilder' of 'method' where
syntax_test/32: Crash # type 'KernelConstructorBuilder' is not a subtype of type 'KernelProcedureBuilder' of 'method' where
syntax_test/33: Crash # type 'KernelConstructorBuilder' is not a subtype of type 'KernelProcedureBuilder' of 'method' where
syntax_test/49: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/54: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/59: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/60: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/61: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/62: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/none: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
syntax_test/none: CompileTimeError
temp_mangling_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
top_level_getter_no_setter1_test/01: RuntimeError
top_level_getter_no_setter2_test/01: RuntimeError
@@ -997,7 +983,6 @@ type_parameter_test/04: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.da
type_parameter_test/05: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
type_parameter_test/06: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
type_parameter_test/none: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
type_variable_bounds_test/10: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
type_variable_closure2_test: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in (local(C.list#)) for j:closure_call(C_list_closure.call).
type_variable_closure3_test: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in (local(C.a#)) for j:closure_call(C_a_closure.call).
type_variable_closure4_test: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in (local(C.map#)) for j:closure_call(C_map_closure.call).
@@ -1009,8 +994,6 @@ type_variable_conflict2_test/09: RuntimeError
type_variable_field_initializer_closure2_test: Crash # Assertion failure: Runtime type information not available for type_variable_local(A.T) in j:closure_call(A_closure.call).
type_variable_field_initializer_closure_test: Crash # Assertion failure: Runtime type information not available for type_variable_local(A.T) in j:closure_call(A_closure.call).
type_variable_function_type_test: RuntimeError
wrong_number_type_arguments_test/00: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
wrong_number_type_arguments_test/02: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
yieldstar_pause_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
[ $compiler == dart2js && $dart2js_with_kernel && $minified ]
@@ -1256,7 +1239,7 @@ main_test/43: Crash # Assertion failure: Cannot find value Instance of 'ThisLoca
main_test/44: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in (local(_LinkedCustomHashSet.#x), local(_LinkedCustomHashSet.#)) for j:closure_call(_LinkedCustomHashSet__LinkedCustomHashSet_closure.call).
main_test/45: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in (local(_LinkedCustomHashSet.#x), local(_LinkedCustomHashSet.#)) for j:closure_call(_LinkedCustomHashSet__LinkedCustomHashSet_closure.call).
malformed_test/06: CompileTimeError
malformed_test/none: RuntimeError
malformed_test/none: Crash # Internal Error: Non-empty instruction stack
many_named_arguments_test: RuntimeError
map_literal4_test: RuntimeError
method_name_test: CompileTimeError
@@ -751,8 +751,6 @@ named_parameters_with_dollars_test: RuntimeError
regress_30339_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
typevariable_substitution2_test/02: RuntimeError
unused_overridden_async_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
wrong_number_type_arguments_test/00: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
wrong_number_type_arguments_test/02: Crash # 'package:front_end/src/fasta/kernel/kernel_class_builder.dart': Failed assertion: line 83 pos 12: 'arguments == null || cls.typeParameters.length == arguments.length': is not true.
yieldstar_pause_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/type_builder.dart': Failed assertion: line 141 pos 12: 'member.isInstanceMember': is not true.
[ $compiler == dart2js && $dart2js_with_kernel && $minified ]