Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 1843453002: Better strong mode least upper bound for interface types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge hell Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/src/task/strong/checker_test.dart
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index 64da0657c2906bf21e5a7c93b1411f0570484d52..74b40ec7e5a590e9db6d2b6ae6cd52dc9170872e 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -62,6 +62,55 @@ void main() {
''');
});
+ test('least upper bounds', () {
+ checkFile('''
+ typedef T Returns<T>();
+
+ // regression test for https://github.com/dart-lang/sdk/issues/26094
+ class A <S extends Returns<S>, T extends Returns<T>> {
+ int test(bool b) {
+ S s;
+ T t;
+ if (b) {
+ return /*warning:RETURN_OF_INVALID_TYPE*/b ? s : t;
+ } else {
+ return /*warning:RETURN_OF_INVALID_TYPE*/s ?? t;
+ }
+ }
+ }
+
+ class B<S, T extends S> {
+ T t;
+ S s;
+ int test(bool b) {
+ return /*warning:RETURN_OF_INVALID_TYPE*/b ? t : s;
+ }
+ }
+
+ class C {
+ // Check that the least upper bound of two types with the same
+ // class but different type arguments produces the pointwise
+ // least upper bound of the type arguments
+ int test1(bool b) {
+ List<int> li;
+ List<double> ld;
+ return /*warning:RETURN_OF_INVALID_TYPE*/b ? li : ld;
+ }
+ // TODO(leafp): This case isn't handled yet. This test checks
+ // the case where two related classes are instantiated with related
+ // but different types.
+ Iterable<num> test2(bool b) {
+ List<int> li;
+ Iterable<double> id;
+ int x =
+ /*info:ASSIGNMENT_CAST should be warning:INVALID_ASSIGNMENT*/
+ b ? li : id;
+ return /*warning:DOWN_CAST_COMPOSITE should be pass*/b ? li : id;
+ }
+ }
+ ''');
+ });
+
test('setter return types', () {
checkFile('''
void voidFn() => null;
@@ -71,7 +120,8 @@ void main() {
void set c(y) => /*warning:RETURN_OF_INVALID_TYPE*/4;
void set d(y) => voidFn();
/*warning:NON_VOID_RETURN_FOR_SETTER*/int set e(y) => 4;
- /*warning:NON_VOID_RETURN_FOR_SETTER*/int set f(y) => /*warning:RETURN_OF_INVALID_TYPE*/voidFn();
+ /*warning:NON_VOID_RETURN_FOR_SETTER*/int set f(y) =>
+ /*warning:RETURN_OF_INVALID_TYPE*/voidFn();
set g(y) {return /*warning:RETURN_OF_INVALID_TYPE*/4;}
void set h(y) {return /*warning:RETURN_OF_INVALID_TYPE*/4;}
/*warning:NON_VOID_RETURN_FOR_SETTER*/int set i(y) {return 4;}

Powered by Google App Engine
This is Rietveld 408576698