forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#1400. Add object pattern tests for extension types
- Loading branch information
Showing
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
LanguageFeatures/Extension-types/static_analysis_extension_types_A32_t01.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,38 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
/// @assertion An extension type V (which may include actual type arguments) can | ||
/// be used in an object pattern (e.g., case V(): ... where V is an extension | ||
/// type). Exhaustiveness analysis will treat such patterns as if they had been | ||
/// an object pattern matching the extension type erasure of V. | ||
/// | ||
/// @description Check that an extension type can be used in an object pattern | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
class C { | ||
int x; | ||
C(this.x); | ||
} | ||
|
||
extension type ET1(C id) {} | ||
extension type ET2(C id) implements C {} | ||
|
||
main() { | ||
var ET1() = ET1(C(0)); | ||
var ET2(x: v1) = ET2(C(1)); | ||
Expect.equals(1, v1); | ||
|
||
var C(x: v2) = ET2(C(2)); | ||
Expect.equals(2, v2); | ||
|
||
var ET1(id: v3) = ET1(C(3)); | ||
Expect.equals(3, v3.x); | ||
|
||
var ET2(id: v4) = ET2(C(4)); | ||
Expect.equals(4, v4.x); | ||
} |
39 changes: 39 additions & 0 deletions
39
LanguageFeatures/Extension-types/static_analysis_extension_types_A32_t02.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,39 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
/// @assertion An extension type V (which may include actual type arguments) can | ||
/// be used in an object pattern (e.g., case V(): ... where V is an extension | ||
/// type). Exhaustiveness analysis will treat such patterns as if they had been | ||
/// an object pattern matching the extension type erasure of V. | ||
/// | ||
/// @description Check that an extension type can be used in an object pattern. | ||
/// Test generics | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
class C<T> { | ||
T x; | ||
C(this.x); | ||
} | ||
|
||
extension type ET1<T>(C<T> id) {} | ||
extension type ET2<T>(C<T> id) implements C<T> {} | ||
|
||
main() { | ||
var ET1<num>() = ET1(C(3.14)); | ||
var ET2<int>(x: v1) = ET2<int>(C(1)); | ||
Expect.equals(1, v1); | ||
|
||
var C<String>(x: v2) = ET2<String>(C<String>("2")); | ||
Expect.equals("2", v2); | ||
|
||
var ET1<String>(id: v3) = ET1(C<String>("3")); | ||
Expect.equals("3", v3.x); | ||
|
||
var ET2<int>(id: v4) = ET2<int>(C(4)); | ||
Expect.equals(4, v4.x); | ||
} |
50 changes: 50 additions & 0 deletions
50
LanguageFeatures/Extension-types/static_analysis_extension_types_A32_t03.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,50 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
/// @assertion An extension type V (which may include actual type arguments) can | ||
/// be used in an object pattern (e.g., case V(): ... where V is an extension | ||
/// type). Exhaustiveness analysis will treat such patterns as if they had been | ||
/// an object pattern matching the extension type erasure of V. | ||
/// | ||
/// @description Check that an extension type erasure is not used in an object | ||
/// pattern outside of switch statements and expressions | ||
/// @author sgrekhov22@gmail.com | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
class C { | ||
int x; | ||
C(this.x); | ||
} | ||
|
||
extension type ET1(C id) {} | ||
extension type ET2(C id) {} | ||
extension type ET3(C id) implements C {} | ||
|
||
main() { | ||
var C(x: v1) = ET1(C(1)); | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
var ET1(x: v2) = ET1(C(2)); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
var ET1() = C(42); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
var ET1() = ET2(C(42)); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
var ET3(x: v3) = C(42); | ||
// ^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
var ET3(x: v4) = ET1(C(42)); | ||
// ^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |