-
Notifications
You must be signed in to change notification settings - Fork 29
#2976. Add more tests for nullable and FutureOr types #3050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
67 changes: 67 additions & 0 deletions
67
LanguageFeatures/Static-access-shorthand/type_inference_A01_t08.dart
This file contains hidden or 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,67 @@ | ||
| // Copyright (c) 2025, 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 A context type scheme is said to denote a declaration in some | ||
| /// cases. Not all context type schemes denote a declaration. | ||
| /// If a type scheme `S`: | ||
| /// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a | ||
| /// declaration `D` which must therefore be a type-introducing declaration, | ||
| /// which currently means a class, mixin, enum or extension type declaration, | ||
| /// then `S` denotes the declaration `D`. | ||
| /// - has the form `S?` or `FutureOr<S>`, and the type scheme S denotes a | ||
| /// declaration D, then so does `S?/FutureOr<S>`. Only the "base type" of the | ||
| /// union type is considered, ensuring that a type scheme denotes at most one | ||
| /// declaration or static namespace. | ||
| /// - has any other form, including type variables, promoted type variables and | ||
| /// `_`, then the type scheme does not denote any declaration or namespace. | ||
| /// | ||
| /// @description Checks that if a shorthand context type schema has one of the | ||
| /// forms `C`, `C<...>`, `C?`, or `C<...>?` and `C` is a type introduced by the | ||
| /// type declaration `D`, then the shorthand context denotes the type | ||
| /// declaration `D`. Test a class. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| // SharedOptions=--enable-experiment=enum-shorthands | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
|
|
||
| class C<T> { | ||
| T value; | ||
| C(this.value); | ||
| C.id(this.value); | ||
| factory C.f(T t) = C; | ||
|
|
||
| static C<int> get staticGetter => C(4); | ||
| static C<X> staticMethod<X>(X x) => C<X>(x); | ||
| static C<String> instance = C("one"); | ||
| } | ||
|
|
||
| main() { | ||
| C? c1 = .new(1); | ||
| Expect.equals(1, c1.value); | ||
|
|
||
| C? c2 = .id(2); | ||
| Expect.equals(2, c2.value); | ||
|
|
||
| C<int>? c3 = .f(3); | ||
| Expect.equals(3, c3.value); | ||
|
|
||
| C<int>? c4 = .staticGetter; | ||
| Expect.equals(4, c4.value); | ||
|
|
||
| C? c5 = .staticGetter; | ||
| Expect.equals(4, c5.value); | ||
|
|
||
| C<int>? c6 = .staticMethod<int>(6); | ||
| Expect.equals(6, c6.value); | ||
|
|
||
| C? c7 = .staticMethod<int>(7); | ||
| Expect.equals(7, c7.value); | ||
|
|
||
| C<String>? c8 = .instance; | ||
| Expect.equals("one", c8.value); | ||
|
|
||
| C? c9 = .instance; | ||
| Expect.equals("one", c9.value); | ||
| } |
70 changes: 70 additions & 0 deletions
70
LanguageFeatures/Static-access-shorthand/type_inference_A01_t09.dart
This file contains hidden or 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,70 @@ | ||
| // Copyright (c) 2025, 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 A context type scheme is said to denote a declaration in some | ||
| /// cases. Not all context type schemes denote a declaration. | ||
| /// If a type scheme `S`: | ||
| /// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a | ||
| /// declaration `D` which must therefore be a type-introducing declaration, | ||
| /// which currently means a class, mixin, enum or extension type declaration, | ||
| /// then `S` denotes the declaration `D`. | ||
| /// - has the form `S?` or `FutureOr<S>`, and the type scheme S denotes a | ||
| /// declaration D, then so does `S?/FutureOr<S>`. Only the "base type" of the | ||
| /// union type is considered, ensuring that a type scheme denotes at most one | ||
| /// declaration or static namespace. | ||
| /// - has any other form, including type variables, promoted type variables and | ||
| /// `_`, then the type scheme does not denote any declaration or namespace. | ||
| /// | ||
| /// @description Checks that if a shorthand context type schema has one of the | ||
| /// forms `FutureOr<C>`, `FutureOr<C<...>>`, `FutureOr<C>?`, | ||
| /// `FutureOr<C<...>>?`, `FutureOr<C?>`, `FutureOr<C<...>?>`, `FutureOr<C?>?` or | ||
| /// `FutureOr<C<...>?>?` and `C` is a type introduced by the type declaration | ||
| /// `D`, then the shorthand context denotes the type declaration `D`. Test a | ||
| /// class. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| // SharedOptions=--enable-experiment=enum-shorthands | ||
|
|
||
| import 'dart:async'; | ||
| import '../../Utils/expect.dart'; | ||
|
|
||
| class C<T> { | ||
| T value; | ||
| C(this.value); | ||
| C.id(this.value); | ||
| factory C.f(T t) = C; | ||
|
|
||
| static C<int> get staticGetter => C(4); | ||
| static C<X> staticMethod<X>(X x) => C<X>(x); | ||
| static C<String> instance = C("one"); | ||
| } | ||
|
|
||
| main() async { | ||
| FutureOr<C?>? c1 = .new(1); | ||
| Expect.equals(1, (await c1)?.value); | ||
|
|
||
| FutureOr<C?>? c2 = .id(2); | ||
| Expect.equals(2, (await c2)?.value); | ||
|
|
||
| FutureOr<C<int>?>? c3 = .f(3); | ||
| Expect.equals(3, (await c3)?.value); | ||
|
|
||
| FutureOr<C<int>?>? c4 = .staticGetter; | ||
| Expect.equals(4, (await c4)?.value); | ||
|
|
||
| FutureOr<C?>? c5 = .staticGetter; | ||
| Expect.equals(4, (await c5)?.value); | ||
|
|
||
| FutureOr<C<int>?>? c6 = .staticMethod<int>(6); | ||
| Expect.equals(6, (await c6)?.value); | ||
|
|
||
| FutureOr<C?>? c7 = .staticMethod<int>(7); | ||
| Expect.equals(7, (await c7)?.value); | ||
|
|
||
| FutureOr<C<String>?>? c8 = .instance; | ||
| Expect.equals("one", (await c8)?.value); | ||
|
|
||
| FutureOr<C?>? c9 = .instance; | ||
| Expect.equals("one", (await c9)?.value); | ||
| } |
68 changes: 68 additions & 0 deletions
68
LanguageFeatures/Static-access-shorthand/type_inference_A01_t10.dart
This file contains hidden or 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,68 @@ | ||
| // Copyright (c) 2025, 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 A context type scheme is said to denote a declaration in some | ||
| /// cases. Not all context type schemes denote a declaration. | ||
| /// If a type scheme `S`: | ||
| /// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a | ||
| /// declaration `D` which must therefore be a type-introducing declaration, | ||
| /// which currently means a class, mixin, enum or extension type declaration, | ||
| /// then `S` denotes the declaration `D`. | ||
| /// - has the form `S?` or `FutureOr<S>`, and the type scheme S denotes a | ||
| /// declaration D, then so does `S?/FutureOr<S>`. Only the "base type" of the | ||
| /// union type is considered, ensuring that a type scheme denotes at most one | ||
| /// declaration or static namespace. | ||
| /// - has any other form, including type variables, promoted type variables and | ||
| /// `_`, then the type scheme does not denote any declaration or namespace. | ||
| /// | ||
| /// @description Checks that if a shorthand context type schema has one of the | ||
| /// forms `C`, `C<...>`, `C?`, or `C<...>?` and `C` is a type introduced by the | ||
| /// type declaration `D`, then the shorthand context denotes the type | ||
| /// declaration `D`. Test a mixin. | ||
| /// @author sgrekhov22@gmail.com | ||
|
|
||
| // SharedOptions=--enable-experiment=enum-shorthands | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
|
|
||
| class C<T> { | ||
| T value; | ||
| C(this.value); | ||
| } | ||
|
|
||
| mixin M<T> on C<T> { | ||
| static M<int> get staticGetter => MC(1); | ||
| static M<X> staticMethod<X>(X x) => MC<X>(x); | ||
| static M<String> instance = MC("one"); | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (other is C) { | ||
| return value == other.value; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| class MC<T> = C<T> with M<T>; | ||
|
|
||
| main() { | ||
| M<int>? m1 = .staticGetter; | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Expect.equals(MC(1), m1); | ||
|
|
||
| M? m2 = .staticGetter; | ||
| Expect.equals(MC(1), m2); | ||
|
|
||
| M<int>? m3 = .staticMethod<int>(3); | ||
| Expect.equals(MC(3), m3); | ||
|
|
||
| M? m4 = .staticMethod<int>(4); | ||
| Expect.equals(MC(4), m4); | ||
|
|
||
| M<String>? m5 = .instance; | ||
| Expect.equals(MC("one"), m5); | ||
|
|
||
| M? m6 = .instance; | ||
| Expect.equals(MC("one"), m6); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.