Skip to content

Commit

Permalink
Create test for language issue 1182
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Lasse R.H. Nielsen <[email protected]>
  • Loading branch information
eernstg authored and [email protected] committed Sep 30, 2020
1 parent d1ca72f commit cd280a3
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit cd280a3

Please sign in to comment.