dart-sdk/tests/web_2/lax_runtime_type_instantiate_to_string_test.dart
Stephen Adams d49d5a96f7 [dart2js] Rti-need fix for generic instantiations
The rti-need of an instantiation is not the same as the rti-need of the
instantiated generic function. The generic function might not use its
type arguments but the instantiation still needs the type arguments for
equality.

dart2js implements generic function instantiation by creating instances
of a helper class that is a subclass of `Closure`. The helper class needs
its type parameters since they are used in `==` and `toString()` methods.
The fix for #47054 is to add the dependency of the helper class type
parameters on the instantiation type arguments.

Change-Id: I9ecb18e1b61a8ad6549f35b572476b1ed7ebb88d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212037
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2021-10-19 23:48:31 +00:00

26 lines
869 B
Dart

// Copyright (c) 2018, 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.
// @dart = 2.7
// dart2jsOptions=--strong --omit-implicit-checks --lax-runtime-type-to-string
import 'package:expect/expect.dart';
main() {
T id<T>(T t) => t;
int Function(int) x = id;
var toString = "${x.runtimeType}";
if ('$Object' == 'Object') {
// `true` if non-minified.
// The signature of `id` is not otherwise needed so the instantiation
// wrapper doesn't have a function type.
// The type parameter is present since it is required because `==`
// distinguishes instantiations of the same generic function with different
// types.
Expect.equals("Instantiation1<int>", toString);
}
print(toString);
}