[fasta] Normalize type arguments as in Dart 1 when not in strong mode
Change-Id: Id25ed6580726610e9e0a108bc42eafe9d88bfc11
Reviewed-on: https://dart-review.googlesource.com/51600
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
diff --git a/pkg/front_end/lib/src/fasta/builder/unresolved_type.dart b/pkg/front_end/lib/src/fasta/builder/unresolved_type.dart
index ef75ed9..c539213 100644
--- a/pkg/front_end/lib/src/fasta/builder/unresolved_type.dart
+++ b/pkg/front_end/lib/src/fasta/builder/unresolved_type.dart
@@ -27,8 +27,8 @@
/// Performs checks on the type after it's resolved.
void checkType() {
- if (builder is NamedTypeBuilder) {
- NamedTypeBuilder resolvedType = builder as NamedTypeBuilder;
+ TypeBuilder resolvedType = builder;
+ if (resolvedType is NamedTypeBuilder) {
TypeDeclarationBuilder declaration = resolvedType.builder;
if (declaration is ClassBuilder) {
if (resolvedType.arguments != null &&
@@ -51,4 +51,25 @@
}
}
}
+
+ /// Normalizes the type arguments in accordance with Dart 1 semantics.
+ void normalizeType() {
+ TypeBuilder resolvedType = builder;
+ if (resolvedType is NamedTypeBuilder) {
+ TypeDeclarationBuilder declaration = resolvedType.builder;
+ if (declaration is ClassBuilder) {
+ if (resolvedType.arguments != null &&
+ resolvedType.arguments.length != declaration.typeVariablesCount) {
+ // [resolveType.arguments] will be normalized later if they are null.
+ resolvedType.arguments = null;
+ }
+ } else if (declaration is FunctionTypeAliasBuilder) {
+ if (resolvedType.arguments != null &&
+ resolvedType.arguments.length != declaration.typeVariablesCount) {
+ // [resolveType.arguments] will be normalized later if they are null.
+ resolvedType.arguments = null;
+ }
+ }
+ }
+ }
}
diff --git a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
index 6def2ba..d1f753c 100644
--- a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
+++ b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
@@ -678,6 +678,8 @@
t.resolveIn(scope);
if (loader.target.strongMode) {
t.checkType();
+ } else {
+ t.normalizeType();
}
}
types.clear();