// 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 on T { T Function(T) get f => (_) => this; } class A { 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 { 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`, erase `S & int` to `S`, bind `T` to `S`. S Function(S) f = s.f; } } } class C { 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() ..testBoundedTypeVariable(1) ..testPromotedTypeVariable(2); B() ..testBoundedTypeVariable(1) ..testPromotedType(2); C() ..testBoundedTypeVariable(1) ..testPromotedType(2); }