From 9d1b5ced65de05e5f35806bd99f569aaf9c6f761 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Sat, 22 Feb 2020 00:34:21 +0000 Subject: [PATCH] [dartdevc] Update instantiated type arguments in tear-offs They now become a `Object*` or `Object?` if the library where the method is defined is legacy or null safe. Change-Id: Ia3de0d728187b9c5bf64cc8c08aa075e63aff942 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136723 Reviewed-by: Sigmund Cherem Reviewed-by: Mark Zhou Commit-Queue: Nicholas Shahan --- pkg/dev_compiler/lib/src/kernel/compiler.dart | 3 +-- .../generic_function_type_equality_test.dart | 12 +++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index e9c589ead85..fbd18bad710 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -1378,8 +1378,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor result = f.computeThisFunctionType(member.enclosingLibrary.nonNullable); } else { DartType reifyParameter(VariableDeclaration p) => isCovariantParameter(p) - ? _coreTypes.objectClass.getThisType( - _coreTypes, _coreTypes.objectClass.enclosingLibrary.nonNullable) + ? _coreTypes.objectRawType(member.enclosingLibrary.nullable) : p.type; NamedType reifyNamedParameter(VariableDeclaration p) => NamedType(p.name, reifyParameter(p)); diff --git a/tests/language/nnbd/type_equality/generic_function_type_equality_test.dart b/tests/language/nnbd/type_equality/generic_function_type_equality_test.dart index fc18cdd88c5..b830ba3cfa8 100644 --- a/tests/language/nnbd/type_equality/generic_function_type_equality_test.dart +++ b/tests/language/nnbd/type_equality/generic_function_type_equality_test.dart @@ -48,7 +48,6 @@ main() { Expect.equals(namedTToVoid.runtimeType, namedSToVoid.runtimeType); Expect.equals( namedNullableTToVoid.runtimeType, namedNullableSToVoid.runtimeType); - Expect.equals(A().fn.runtimeType, legacy.A().fn.runtimeType); Expect.equals(requiredTToVoid.runtimeType, requiredSToVoid.runtimeType); Expect.equals( requiredNullableTToVoid.runtimeType, requiredNullableSToVoid.runtimeType); @@ -62,12 +61,11 @@ main() { optionalTToVoid.runtimeType, legacy.optionalRToVoid.runtimeType); Expect.notEquals(namedTToVoid.runtimeType, legacy.namedRToVoid.runtimeType); - // TODO(nshahan) What should the bound be of the type arguments in the - // tearoffs? Object?, Object*, B etc? - Expect.equals(A().fn.runtimeType, legacy.A().fn.runtimeType); - Expect.equals(A().fn.runtimeType, legacy.rawAFnTearoff.runtimeType); - Expect.equals(A().fn.runtimeType, legacy.A().fn.runtimeType); - Expect.equals(A().fn.runtimeType, legacy.A().fn.runtimeType); + // Type arguments in methods tear-offs from null safe libraries become Object? + // and Object* from legacy libraries and are not equal. + Expect.notEquals(A().fn.runtimeType, legacy.A().fn.runtimeType); + Expect.notEquals(A().fn.runtimeType, legacy.rawAFnTearoff.runtimeType); + Expect.notEquals(A().fn.runtimeType, legacy.A().fn.runtimeType); // Same signatures but one is from a legacy library. Expect.equals(positionalTToVoidWithBound.runtimeType,