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. More static analysis of the inline class tests
- Loading branch information
Showing
14 changed files
with
671 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_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,55 @@ | ||
// 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. | ||
|
||
// 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 Assume that T1, .. Ts are types, and V resolves to an inline | ||
/// class declaration of the following form: | ||
/// | ||
/// inline class V<X1 extends B1, .. Xs extends Bs> ... { | ||
/// final T id; | ||
/// V(this.id); | ||
/// | ||
/// ... // Other members. | ||
/// } | ||
/// ... | ||
/// When s is zero, V<T1, .. Ts> simply stands for V, a non-generic inline type. | ||
/// When s is greater than zero, a raw occurrence V is treated like a raw type: | ||
/// Instantiation to bound is used to obtain the omitted type arguments | ||
/// | ||
/// @description Checks that instantiation to bound is used to obtain the | ||
/// omitted type arguments | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/static_type_helper.dart"; | ||
|
||
inline class V1<T extends num> { | ||
final int id; | ||
V1(this.id); | ||
} | ||
|
||
inline class V2<T extends Object> { | ||
final int id; | ||
V2(this.id); | ||
} | ||
|
||
inline class V3<T extends Object?> { | ||
final int id; | ||
V3(this.id); | ||
} | ||
|
||
main() { | ||
var v1 = V1(42); | ||
v1.expectStaticType<Exactly<V1<num>>>(); | ||
|
||
var v2 = V2(42); | ||
v2.expectStaticType<Exactly<V2<Object>>>(); | ||
|
||
var v3 = V3(42); | ||
v3.expectStaticType<Exactly<V3<Object?>>>(); | ||
} |
41 changes: 41 additions & 0 deletions
41
LanguageFeatures/Inline-classes/static_analysis_inline_class_A05_t04.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,41 @@ | ||
// 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. | ||
|
||
// 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 Assume that T1, .. Ts are types, and V resolves to an inline | ||
/// class declaration of the following form: | ||
/// | ||
/// inline class V<X1 extends B1, .. Xs extends Bs> ... { | ||
/// final T id; | ||
/// V(this.id); | ||
/// | ||
/// ... // Other members. | ||
/// } | ||
/// ... | ||
/// When s is zero, V<T1, .. Ts> simply stands for V, a non-generic inline type. | ||
/// When s is greater than zero, a raw occurrence V is treated like a raw type: | ||
/// Instantiation to bound is used to obtain the omitted type arguments | ||
/// | ||
/// @description Checks that instantiation to bound is used to obtain the | ||
/// omitted type arguments. Test default bound | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
inline class V1<T> { | ||
final int id; | ||
V1(this.id); | ||
|
||
Type get type => T; | ||
} | ||
|
||
main() { | ||
var v1 = V1(42); | ||
Expect.equals(dynamic, v1.type); | ||
} |
36 changes: 36 additions & 0 deletions
36
LanguageFeatures/Inline-classes/static_analysis_inline_class_A09_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,36 @@ | ||
// 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 If e is an expression whose static type V is the inline type | ||
/// Inline<T1, .. Ts> and m is the name of a member that V has, a member access | ||
/// like e.m(args) is treated as an invocation of the inline member m on the | ||
/// receiver e according to the inline type Inline and with the actual type | ||
/// arguments T1, ..., Ts, with the actual argument part args. | ||
/// | ||
/// @description Checks that a member access `e.m(args)` is treated as an | ||
/// invocation of the inline member m on the receiver `e` according to the | ||
/// inline type `Inline` and with the actual type arguments `T1, ..., Ts`, with | ||
/// the actual argument part `args`. | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/static_type_helper.dart"; | ||
|
||
inline class V1<T> { | ||
final T id; | ||
V1(this.id); | ||
|
||
(Map<K, V>, T) asMap<K, V>() => (<K, V>{}, id); | ||
} | ||
|
||
main() { | ||
V1<num> v1 = V1(42); | ||
v1.asMap<String, bool>() | ||
.expectStaticType<Exactly<(Map<String, bool>, num)>>(); | ||
|
||
V1<String> v2 = V1("42"); | ||
v2.asMap<String, String>() | ||
.expectStaticType<Exactly<(Map<String, String>, String)>>(); | ||
} |
32 changes: 32 additions & 0 deletions
32
LanguageFeatures/Inline-classes/static_analysis_inline_class_A10_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,32 @@ | ||
// 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 Similarly, e.m is treated an invocation of the inline member m on | ||
/// the receiver e according to the inline type Inline and with the actual type | ||
/// arguments T1, ..., Ts and no actual argument part. | ||
/// | ||
/// @description Checks that a member access `e.m` is treated as an invocation | ||
/// of the inline member `m` on the receiver `e` according to the inline type | ||
/// `Inline` and with the actual type arguments `T1, ..., Ts` and no actual | ||
/// argument part | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/static_type_helper.dart"; | ||
|
||
inline class V1<T, K, V> { | ||
final T id; | ||
V1(this.id); | ||
|
||
(Map<K, V>, T) get asMap => (<K, V>{}, id); | ||
} | ||
|
||
main() { | ||
V1<num, String, bool> v1 = V1(42); | ||
v1.asMap.expectStaticType<Exactly<(Map<String, bool>, num)>>(); | ||
|
||
V1<String, String, Null> v2 = V1("42"); | ||
v2.asMap.expectStaticType<Exactly<(Map<String, Null>, String)>>(); | ||
} |
36 changes: 36 additions & 0 deletions
36
LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_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,36 @@ | ||
// 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 If e is an expression whose static type V is the inline type | ||
/// Inline<T1, .. Ts> and V has no member whose basename is the basename of m, | ||
/// a member access like e.m(args) may be an extension member access, following | ||
/// the normal rules about applicability and accessibility of extensions, in | ||
/// particular that V must match the on-type of the extension. | ||
/// | ||
/// @description Checks that if `V` has no member with the name `m`, but there | ||
/// is an extension member `m` then it is invoked | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension Ex1 on V { | ||
String foo() => "Ex1.foo()"; | ||
} | ||
|
||
extension Ex2 on int { | ||
String bar() => "Ex2.bar()"; | ||
} | ||
|
||
inline class V { | ||
final int id; | ||
V(this.id); | ||
} | ||
|
||
main() { | ||
V v = V(42); | ||
Expect.equals("Ex1.foo()", v.foo()); | ||
Expect.equals("Ex2.bar()", v.id.bar()); | ||
} |
41 changes: 41 additions & 0 deletions
41
LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_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,41 @@ | ||
// 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 If e is an expression whose static type V is the inline type | ||
/// Inline<T1, .. Ts> and V has no member whose basename is the basename of m, | ||
/// a member access like e.m(args) may be an extension member access, following | ||
/// the normal rules about applicability and accessibility of extensions, in | ||
/// particular that V must match the on-type of the extension. | ||
/// | ||
/// @description Checks that it is a compile-time error if `V` has no member | ||
/// with name `m` and there is no extension member with the name `m` | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension Ex1 on V { | ||
String foo() => "Ex1.foo()"; | ||
} | ||
|
||
extension Ex2 on int { | ||
String bar() => "Ex2.bar()"; | ||
} | ||
|
||
inline class V { | ||
final int id; | ||
V(this.id); | ||
} | ||
|
||
main() { | ||
V v = V(42); | ||
v.bar(); | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
v.id.foo(); | ||
// ^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
43 changes: 43 additions & 0 deletions
43
LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_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,43 @@ | ||
// 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 If e is an expression whose static type V is the inline type | ||
/// Inline<T1, .. Ts> and V has no member whose basename is the basename of m, | ||
/// a member access like e.m(args) may be an extension member access, following | ||
/// the normal rules about applicability and accessibility of extensions, in | ||
/// particular that V must match the on-type of the extension. | ||
/// | ||
/// @description Checks that if `V` has no member with the name `m`, but there | ||
/// is an extension member `m` then it is invoked | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
extension Ex1 on V<String> { | ||
String foo() => "Ex1.foo()"; | ||
} | ||
|
||
extension Ex2 on V<int> { | ||
String foo() => "Ex2.foo()"; | ||
} | ||
|
||
extension Ex3 on int { | ||
String foo() => "Ex3.foo()"; | ||
} | ||
|
||
inline class V<T> { | ||
final T id; | ||
V(this.id); | ||
} | ||
|
||
main() { | ||
V<String> v1 = V("42"); | ||
Expect.equals("Ex1.foo()", v1.foo()); | ||
|
||
V<int> v2 = V(42); | ||
Expect.equals("Ex2.foo()", v2.foo()); | ||
Expect.equals("Ex3.foo()", v2.id.foo()); | ||
} |
80 changes: 80 additions & 0 deletions
80
LanguageFeatures/Inline-classes/static_analysis_inline_class_A11_t04.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,80 @@ | ||
// 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 If e is an expression whose static type V is the inline type | ||
/// Inline<T1, .. Ts> and V has no member whose basename is the basename of m, | ||
/// a member access like e.m(args) may be an extension member access, following | ||
/// the normal rules about applicability and accessibility of extensions, in | ||
/// particular that V must match the on-type of the extension. | ||
/// | ||
/// @description Checks that it is a compile-time error if `V` has no member | ||
/// with name `m` and there is no extension member with the name `m` | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=inline-class | ||
|
||
extension Ex1 on V<String> { | ||
String fooString() => "fooString"; | ||
} | ||
|
||
extension Ex2 on V<int> { | ||
String fooInt() => "fooInt"; | ||
} | ||
|
||
extension Ex3 on String { | ||
String barString() => "barString"; | ||
} | ||
|
||
extension Ex4 on int { | ||
String barInt() => "barInt"; | ||
} | ||
|
||
inline class V<T> { | ||
final T id; | ||
V(this.id); | ||
} | ||
|
||
main() { | ||
V<String> v1 = V("42"); | ||
v1.fooInt(); | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
v1.id.fooString(); | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
v1.barString(); | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
v1.barInt(); | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
V<int> v2 = V(42); | ||
v2.fooString(); | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
v2.id.fooInt(); | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
v2.barString(); | ||
// ^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
v2.barInt(); | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
Oops, something went wrong.