-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove incorrect super bounded test, and add tests for bounds
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
1 parent
c565fbf
commit 7b46191
Showing
2 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
tests/language_2/extension_methods/static_extension_bounds_error_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters