Skip to content

Commit

Permalink
Remove incorrect super bounded test, and add tests for bounds
Browse files Browse the repository at this point in the history
violations in extension method applications.

Fix #37765

Change-Id: I26d286251b0e832577dc170b9a41594c52e25377
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112149
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
leafpetersen authored and commit-bot@chromium.org committed Aug 7, 2019
1 parent c565fbf commit 7b46191
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright (c) 2019, 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.

// SharedOptions=--enable-experiment=extension-methods

// Tests bounds checking for extension methods

extension E1<T extends num> on T {
int get e1 => 1;
}

extension E2<T extends S, S extends num> on T {
int get e2 => 2;
}

extension E3<T> on T {
S f3<S extends T>(S x) => x;
}

extension E4<T extends Rec<T>> on T {
int get e4 => 4;
}

class Rec<T extends Rec<T>> {}

class RecSolution extends Rec<RecSolution> {}


void main() {
String s = "s";
int i = 0;
double d = 1.0;

// Inferred type of String does not satisfy the bound.
s.e1;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E1(s).e1;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E1<String>(s).e1;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

// Inferred types of int and double are ok
i.e1;
E1(i).e1;
E1<int>(i).e1;
d.e1;
E1(d).e1;
E1<double>(d).e1;

// Inferred type of String does not satisfy the bound.
s.e2;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E2(s).e2;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E2<String, num>(s).e2;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

// Inferred types of int and double are ok
i.e2;
E2(i).e2;
E2<int, num>(i).e2;
d.e2;
E2(d).e2;
E2<double, num>(d).e2;

// Inferred type int for method type parameter doesn't match the inferred
// bound of String
s.f3(3);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E3(s).f3(3);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E3<String>(s).f3(3);
// ^^
// [analyzer] unspecified
// [cfe] unspecified

// Inferred type int for method type parameter is ok
i.f3(3);
E3(i).f3(3);
E3<int>(i).f3(3);

// Inferred type int for method type parameter doesn't match the inferred
// bound of double
d.f3(3);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E3(d).f3(3);
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E3<double>(d).f3(3);
// ^^
// [analyzer] unspecified
// [cfe] unspecified

RecSolution recs = RecSolution();
Rec<dynamic> superRec = RecSolution(); // Super-bounded type.

// Inferred type of RecSolution is ok
recs.e4;
E4(recs).e4;
E4<RecSolution>(recs).e4;

// Inferred super-bounded type is invalid as type argument
superRec.e4;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E4(superRec).e4;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
E4<Rec<dynamic>>(superRec).e4;
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ main() {
List<num> numList = <int>[];
Pair<int, double> numPair = Pair(1, 2.5);
RecSolution recs = RecSolution();
Rec<Object> superRec = RecSolution(); // Super-bounded type.

Expect.equals(0, object.e0);
Expect.equals(0, list.e0);
Expand Down Expand Up @@ -71,13 +70,11 @@ main() {
checkStaticType<List<num>>(numList.list17);

Expect.equals(0, object.e19);
Expect.equals(0, superRec.e19);
Expect.equals(19, recs.e19);
Expect.type<RecSolution>(recs.list19);
checkStaticType<RecSolution>(recs.list19);

Expect.equals(0, object.e20);
Expect.equals(0, superRec.e20);
Expect.equals(20, recs.e20);
Expect.type<RecSolution>(recs.list20);
checkStaticType<RecSolution>(recs.list20);
Expand Down

0 comments on commit 7b46191

Please sign in to comment.