diff --git a/pkg/compiler/lib/src/elements/types.dart b/pkg/compiler/lib/src/elements/types.dart index ce038a92bdb6..8ae41d313dab 100644 --- a/pkg/compiler/lib/src/elements/types.dart +++ b/pkg/compiler/lib/src/elements/types.dart @@ -2114,12 +2114,14 @@ abstract class DartTypes { String sName = sNamed[sIndex++]; int comparison = sName.compareTo(tName); if (comparison > 0) return false; - bool sIsRequired = sRequiredNamed.contains(sName); + bool sIsRequired = + !useLegacySubtyping && sRequiredNamed.contains(sName); if (comparison < 0) { if (sIsRequired) return false; continue; } - bool tIsRequired = tRequiredNamed.contains(tName); + bool tIsRequired = + !useLegacySubtyping && tRequiredNamed.contains(tName); if (sIsRequired && !tIsRequired) return false; if (!_isSubtype( tNamedTypes[tIndex], sNamedTypes[sIndex - 1], env)) @@ -2127,8 +2129,10 @@ abstract class DartTypes { break; } } - while (sIndex < sNamedLength) { - if (sRequiredNamed.contains(sNamed[sIndex++])) return false; + if (!useLegacySubtyping) { + while (sIndex < sNamedLength) { + if (sRequiredNamed.contains(sNamed[sIndex++])) return false; + } } return true; } finally { diff --git a/pkg/compiler/lib/src/ir/visitors.dart b/pkg/compiler/lib/src/ir/visitors.dart index 6ff419b33186..bd1929e7183a 100644 --- a/pkg/compiler/lib/src/ir/visitors.dart +++ b/pkg/compiler/lib/src/ir/visitors.dart @@ -130,12 +130,10 @@ class DartTypeConverter extends ir.DartTypeVisitor { .skip(node.requiredParameterCount) .toList()), node.namedParameters.map((n) => n.name).toList(), - _options.useLegacySubtyping - ? const {} - : node.namedParameters - .where((n) => n.isRequired) - .map((n) => n.name) - .toSet(), + node.namedParameters + .where((n) => n.isRequired) + .map((n) => n.name) + .toSet(), node.namedParameters.map((n) => visitType(n.type)).toList(), typeVariables ?? const []); DartType type = _convertNullability(functionType, node.nullability); diff --git a/pkg/compiler/lib/src/js_model/element_map_impl.dart b/pkg/compiler/lib/src/js_model/element_map_impl.dart index e92f9f17535b..c4437cd38cd2 100644 --- a/pkg/compiler/lib/src/js_model/element_map_impl.dart +++ b/pkg/compiler/lib/src/js_model/element_map_impl.dart @@ -917,7 +917,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap { for (ir.VariableDeclaration variable in sortedNamedParameters) { namedParameters.add(variable.name); namedParameterTypes.add(getParameterType(variable)); - if (variable.isRequired && !options.useLegacySubtyping) { + if (variable.isRequired) { requiredNamedParameters.add(variable.name); } } diff --git a/pkg/compiler/lib/src/kernel/element_map_impl.dart b/pkg/compiler/lib/src/kernel/element_map_impl.dart index 386f119265b6..0c1c106ae60f 100644 --- a/pkg/compiler/lib/src/kernel/element_map_impl.dart +++ b/pkg/compiler/lib/src/kernel/element_map_impl.dart @@ -539,7 +539,7 @@ class KernelToElementMapImpl implements KernelToElementMap, IrToElementMap { for (ir.VariableDeclaration variable in sortedNamedParameters) { namedParameters.add(variable.name); namedParameterTypes.add(getParameterType(variable)); - if (variable.isRequired && !options.useLegacySubtyping) { + if (variable.isRequired) { requiredNamedParameters.add(variable.name); } } diff --git a/sdk/lib/_internal/js_runtime/lib/rti.dart b/sdk/lib/_internal/js_runtime/lib/rti.dart index aceef480b71b..2f59b9df20d6 100644 --- a/sdk/lib/_internal/js_runtime/lib/rti.dart +++ b/sdk/lib/_internal/js_runtime/lib/rti.dart @@ -2913,12 +2913,14 @@ bool _isFunctionSubtype( String sName = _Utils.asString(_Utils.arrayAt(sNamed, sIndex)); sIndex += 3; if (_Utils.stringLessThan(tName, sName)) return false; - bool sIsRequired = _Utils.asBool(_Utils.arrayAt(sNamed, sIndex - 2)); + bool sIsRequired = !JS_GET_FLAG('LEGACY') && + _Utils.asBool(_Utils.arrayAt(sNamed, sIndex - 2)); if (_Utils.stringLessThan(sName, tName)) { if (sIsRequired) return false; continue; } - bool tIsRequired = _Utils.asBool(_Utils.arrayAt(tNamed, tIndex + 1)); + bool tIsRequired = !JS_GET_FLAG('LEGACY') && + _Utils.asBool(_Utils.arrayAt(tNamed, tIndex + 1)); if (sIsRequired && !tIsRequired) return false; Rti sType = _Utils.asRti(_Utils.arrayAt(sNamed, sIndex - 1)); Rti tType = _Utils.asRti(_Utils.arrayAt(tNamed, tIndex + 2)); @@ -2926,9 +2928,11 @@ bool _isFunctionSubtype( break; } } - while (sIndex < sNamedLength) { - if (_Utils.asBool(_Utils.arrayAt(sNamed, sIndex + 1))) return false; - sIndex += 3; + if (!JS_GET_FLAG('LEGACY')) { + while (sIndex < sNamedLength) { + if (_Utils.asBool(_Utils.arrayAt(sNamed, sIndex + 1))) return false; + sIndex += 3; + } } return true; } diff --git a/tests/dart2js/internal/rti/required_named_parameters_test.dart b/tests/dart2js/internal/rti/required_named_parameters_test.dart index 309a38137936..c07f7a485d62 100644 --- a/tests/dart2js/internal/rti/required_named_parameters_test.dart +++ b/tests/dart2js/internal/rti/required_named_parameters_test.dart @@ -51,11 +51,11 @@ main() { // Subtype may not redeclare optional parameters as required rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b!A,c!A})"); - Expect.isFalse(rti.testingIsSubtype(universe, rti2, rti1)); + Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); // Subtype may not declare new required named parameters rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b:A,c!A,d!A})"); - Expect.isFalse(rti.testingIsSubtype(universe, rti2, rti1)); + Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); // Rti.toString() appears as expected Expect.equals('(B, {required B a, B b, required B c}) => dynamic', diff --git a/tests/dart2js_2/internal/rti/required_named_parameters_test.dart b/tests/dart2js_2/internal/rti/required_named_parameters_test.dart index 309a38137936..c07f7a485d62 100644 --- a/tests/dart2js_2/internal/rti/required_named_parameters_test.dart +++ b/tests/dart2js_2/internal/rti/required_named_parameters_test.dart @@ -51,11 +51,11 @@ main() { // Subtype may not redeclare optional parameters as required rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b!A,c!A})"); - Expect.isFalse(rti.testingIsSubtype(universe, rti2, rti1)); + Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); // Subtype may not declare new required named parameters rti2 = rti.testingUniverseEval(universe, "@(A,{a!A,b:A,c!A,d!A})"); - Expect.isFalse(rti.testingIsSubtype(universe, rti2, rti1)); + Expect.equals(isWeakMode, rti.testingIsSubtype(universe, rti2, rti1)); // Rti.toString() appears as expected Expect.equals('(B, {required B a, B b, required B c}) => dynamic',