From e8daaefabf6687665a0a622580e028bcdc98885f Mon Sep 17 00:00:00 2001 From: Mayank Patke Date: Fri, 26 Jun 2020 21:27:38 +0000 Subject: [PATCH] [dart2js] Ensure generic local functions are marked as potentially needing type arguments. Change-Id: I50831df2530395b9ec3562be171422b0b6455335 Bug: https://github.com/dart-lang/sdk/issues/42501 Fixes: https://github.com/dart-lang/sdk/issues/42501 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152606 Commit-Queue: Mayank Patke Reviewed-by: Stephen Adams --- .../src/js_backend/runtime_types_resolution.dart | 3 +++ .../test/rti/data/local_function_generic.dart | 2 +- .../data/local_function_signatures_generic.dart | 14 +++++++------- tests/dart2js/42501_test.dart | 16 ++++++++++++++++ tests/dart2js_2/42501_test.dart | 16 ++++++++++++++++ 5 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 tests/dart2js/42501_test.dart create mode 100644 tests/dart2js_2/42501_test.dart diff --git a/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart b/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart index d633266ca0d..8259c10ae77 100644 --- a/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart +++ b/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart @@ -1071,6 +1071,9 @@ class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder { // TODO(johnniwinther): Use register generic instantiations // instead. assumeInstantiations: _genericInstantiations.isNotEmpty)) { + if (functionType.typeVariables.isNotEmpty) { + potentiallyNeedTypeArguments(function); + } functionType.forEachTypeVariable((TypeVariableType typeVariable) { Entity typeDeclaration = typeVariable.element.typeDeclaration; if (!processedEntities.contains(typeDeclaration)) { diff --git a/pkg/compiler/test/rti/data/local_function_generic.dart b/pkg/compiler/test/rti/data/local_function_generic.dart index e591bc2712a..2a08e7c4a38 100644 --- a/pkg/compiler/test/rti/data/local_function_generic.dart +++ b/pkg/compiler/test/rti/data/local_function_generic.dart @@ -8,7 +8,7 @@ import 'package:expect/expect.dart'; method1() { /*spec.direct,explicit=[local.T*],needsArgs,needsSignature*/ - /*prod.needsSignature*/ + /*prod.needsArgs,needsSignature*/ T local(T t) => t; return local; } diff --git a/pkg/compiler/test/rti/data/local_function_signatures_generic.dart b/pkg/compiler/test/rti/data/local_function_signatures_generic.dart index be9d7b25428..93b62e8923e 100644 --- a/pkg/compiler/test/rti/data/local_function_signatures_generic.dart +++ b/pkg/compiler/test/rti/data/local_function_signatures_generic.dart @@ -8,7 +8,7 @@ import 'package:expect/expect.dart'; class Class1 { method1() { - /*needsSignature*/ + /*needsArgs,needsInst=[,,],needsSignature*/ num local(num n) => null; return local; } @@ -19,7 +19,7 @@ class Class1 { } method3() { - /*needsSignature*/ + /*needsArgs,needsInst=[,,],needsSignature*/ int local(num n) => null; return local; } @@ -75,13 +75,13 @@ method9() { method10() { /*spec.direct,explicit=[local.T*],needsArgs,needsInst=[,,],needsSignature*/ - /*prod.needsSignature*/ + /*prod.needsArgs,needsInst=[,,],needsSignature*/ num local(T n) => null; return local; } method11() { - /*needsSignature*/ + /*needsArgs,needsInst=[,,],needsSignature*/ T local(num n) => null; return local; } @@ -93,20 +93,20 @@ method12() { } num Function(num) method13() { - /*needsSignature*/ + /*needsArgs,needsInst=[,,],needsSignature*/ num local(num n) => null; return local; } num Function(num) method14() { /*spec.direct,explicit=[local.T*],needsArgs,needsInst=[,,],needsSignature*/ - /*prod.needsSignature*/ + /*prod.needsArgs,needsInst=[,,],needsSignature*/ num local(T n) => null; return local; } num Function(num) method15() { - /*needsSignature*/ + /*needsArgs,needsInst=[,,],needsSignature*/ T local(num n) => null; return local; } diff --git a/tests/dart2js/42501_test.dart b/tests/dart2js/42501_test.dart new file mode 100644 index 00000000000..91b79703025 --- /dev/null +++ b/tests/dart2js/42501_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:expect/expect.dart'; + +typedef F = num? Function(); + +F foo() { + T? local() => null; + return local; +} + +void main() { + Expect.type(foo()); +} diff --git a/tests/dart2js_2/42501_test.dart b/tests/dart2js_2/42501_test.dart new file mode 100644 index 00000000000..ae894135331 --- /dev/null +++ b/tests/dart2js_2/42501_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:expect/expect.dart'; + +typedef F = num Function(); + +F foo() { + T local() => null; + return local; +} + +void main() { + Expect.type(foo()); +}