Create test for language issue 1182
Add language/extension_methods/static_extension_resolution_7_test.dart,
testing that the inference of a type argument to an extension method
invocation treats bounded type variables and promoted type variables
as specified, and as discussed in language issue #1182.
Change-Id: I99f358eb82dcce235edb091bc2bae172c2725d39
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165022
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
diff --git a/tests/language/extension_methods/static_extension_resolution_7_test.dart b/tests/language/extension_methods/static_extension_resolution_7_test.dart
new file mode 100644
index 0000000..96c1712
--- /dev/null
+++ b/tests/language/extension_methods/static_extension_resolution_7_test.dart
@@ -0,0 +1,65 @@
+// 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";
+
+// Tests the resolution of a bare type variable with bounded or promoted type.
+
+extension E<T> on T {
+ T Function(T) get f => (_) => this;
+}
+
+class A<S extends num> {
+ void testBoundedTypeVariable(S s) {
+ // Check that `num` has no `f` so E is applicable, then bind `T` to `S`.
+ S Function(S) f = s.f;
+ }
+
+ void testPromotedTypeVariable(S s) {
+ if (s is int) {
+ // Check that `int` has no `f`, erase `S & int` to `S`, bind `T` to `S`.
+ S Function(S) f = s.f;
+ }
+ }
+}
+
+class B<S extends dynamic> {
+ void testBoundedTypeVariable(S s) {
+ // `dynamic` considered to have `f`, E not applicable, dynamic invocation.
+ Expect.throws(() => s.f);
+ }
+
+ void testPromotedType(S s) {
+ if (s is int) {
+ // Check that `int` has no `f`, bind `T` to `int`.
+ int Function(int) f = s.f;
+ }
+ }
+}
+
+class C<S> {
+ void testBoundedTypeVariable(S s) {
+ // Check that `Object?` has no `f` so E is applicable, then bind `T` to `S`.
+ S Function(S) f = s.f;
+ }
+
+ void testPromotedType(S s) {
+ if (s is int) {
+ // Check that `int` has no `f`, bind `T` to `S`.
+ S Function(S) f = s.f;
+ }
+ }
+}
+
+void main() {
+ A<int>()
+ ..testBoundedTypeVariable(1)
+ ..testPromotedTypeVariable(2);
+ B<int>()
+ ..testBoundedTypeVariable(1)
+ ..testPromotedType(2);
+ C<int>()
+ ..testBoundedTypeVariable(1)
+ ..testPromotedType(2);
+}