From 7b46191f45e33f2ca0528c41fa39b39227b5c4e6 Mon Sep 17 00:00:00 2001 From: Leaf Petersen Date: Wed, 7 Aug 2019 19:36:24 +0000 Subject: [PATCH] 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 Reviewed-by: Erik Ernst Reviewed-by: Brian Wilkerson --- .../static_extension_bounds_error_test.dart | 135 ++++++++++++++++++ .../static_extension_syntax_test.dart | 3 - 2 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 tests/language_2/extension_methods/static_extension_bounds_error_test.dart diff --git a/tests/language_2/extension_methods/static_extension_bounds_error_test.dart b/tests/language_2/extension_methods/static_extension_bounds_error_test.dart new file mode 100644 index 000000000000..5ee6ce16bddf --- /dev/null +++ b/tests/language_2/extension_methods/static_extension_bounds_error_test.dart @@ -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 on T { + int get e1 => 1; +} + +extension E2 on T { + int get e2 => 2; +} + +extension E3 on T { + S f3(S x) => x; +} + +extension E4> on T { + int get e4 => 4; +} + +class Rec> {} + +class RecSolution extends Rec {} + + +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(s).e1; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + // Inferred types of int and double are ok + i.e1; + E1(i).e1; + E1(i).e1; + d.e1; + E1(d).e1; + E1(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(s).e2; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + // Inferred types of int and double are ok + i.e2; + E2(i).e2; + E2(i).e2; + d.e2; + E2(d).e2; + E2(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(s).f3(3); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + // Inferred type int for method type parameter is ok + i.f3(3); + E3(i).f3(3); + E3(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(d).f3(3); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + + RecSolution recs = RecSolution(); + Rec superRec = RecSolution(); // Super-bounded type. + + // Inferred type of RecSolution is ok + recs.e4; + E4(recs).e4; + E4(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>(superRec).e4; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} \ No newline at end of file diff --git a/tests/language_2/extension_methods/static_extension_syntax_test.dart b/tests/language_2/extension_methods/static_extension_syntax_test.dart index 036bcf815f09..2e6c8111dc87 100644 --- a/tests/language_2/extension_methods/static_extension_syntax_test.dart +++ b/tests/language_2/extension_methods/static_extension_syntax_test.dart @@ -18,7 +18,6 @@ main() { List numList = []; Pair numPair = Pair(1, 2.5); RecSolution recs = RecSolution(); - Rec superRec = RecSolution(); // Super-bounded type. Expect.equals(0, object.e0); Expect.equals(0, list.e0); @@ -71,13 +70,11 @@ main() { checkStaticType>(numList.list17); Expect.equals(0, object.e19); - Expect.equals(0, superRec.e19); Expect.equals(19, recs.e19); Expect.type(recs.list19); checkStaticType(recs.list19); Expect.equals(0, object.e20); - Expect.equals(0, superRec.e20); Expect.equals(20, recs.e20); Expect.type(recs.list20); checkStaticType(recs.list20);