[dart2js] Fix a bug with substitution of type variables and NNBD.

Change-Id: I5c5f6152b2f1c25a1ba0b3800023b550b8fabca0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136981
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Joshua Litt 2020-02-24 22:17:09 +00:00 committed by commit-bot@chromium.org
parent d2c9f906e8
commit 2596c20486
3 changed files with 17 additions and 14 deletions

View file

@ -1354,9 +1354,13 @@ class SimpleDartTypeSubstitutionVisitor
@override
DartType substituteTypeVariableType(
TypeVariableType type, Null _, bool freshReference) {
int index = this.parameters.indexOf(type);
if (index != -1) {
return this.arguments[index];
// We need to manually compare types to explicitly ignore nullability on all
// substitutions.
for (int i = 0; i < this.parameters.length; i++) {
var t = this.parameters[i];
if (t is TypeVariableType && t.element == type.element) {
return this.arguments[i];
}
}
// The type variable was not substituted.
return type;
@ -1365,11 +1369,15 @@ class SimpleDartTypeSubstitutionVisitor
@override
DartType substituteFunctionTypeVariable(
covariant FunctionTypeVariable type, Null _, bool freshReference) {
int index = this.parameters.indexOf(type);
if (index != -1) {
return this.arguments[index];
// We need to manually compare types to explicitly ignore nullability on all
// substitutions.
for (int i = 0; i < this.parameters.length; i++) {
var t = this.parameters[i];
if (t is FunctionTypeVariable && t.index == type.index) {
return this.arguments[i];
}
}
// The function type variable was not substituted.
// The type variable was not substituted.
return type;
}
}

View file

@ -265,6 +265,7 @@ abstract class OrderedTypeSetBuilderBase implements OrderedTypeSetBuilder {
InterfaceType existingType = link.head;
if (existingType == type) return;
if (existingType.element == type.element) {
if (existingType.nullability != type.nullability) return;
assert(false, failedAt(cls, 'Invalid ordered typeset for $cls'));
return;
}

View file

@ -72,14 +72,8 @@ application_snapshot("dart2js") {
if (use_nnbd) {
training_args += [ "--enable-experiment=non-nullable" ]
# TODO(joshualitt): restore training with full dart2js. The major known
# issue is missing runtime type information in certain cases.
training_args +=
[ rebase_path("../../tests/language_2/abstract/equal_test.dart") ]
} else {
training_args += [ rebase_path("$target_gen_dir/dart2js.dart") ]
}
training_args += [ rebase_path("$target_gen_dir/dart2js.dart") ]
}
compile_platform("compile_dart2js_platform") {