Skip to content
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

Removed incorrect claim about promotability #3339

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ leaves, and nothing else.
```dart
extension type TinyJson(Object it) {
Iterable<num> get leaves sync* {
final it = this.it; // To get promotion.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope it will be val one day.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, cf. #3332. ;-)

if (it is num) {
yield it;
} else if (it is List<dynamic>) {
Expand All @@ -293,9 +294,6 @@ void main() {
}
```

Note that `it` is subject to promotion in the above example. This is safe
because there is no way to override this would-be final instance variable.

An instance creation of an extension type, `V<T>(o)`, will evaluate to a
reference to the representation object, with the static type `V<T>` (and
there is no object at run time that represents the extension type itself).
Expand Down Expand Up @@ -356,11 +354,11 @@ class TinyJson {
TinyJson(this.it);

Iterable<num> get leaves sync* {
var localIt = it; // To get promotion.
if (localIt is num) {
yield localIt;
} else if (localIt is List<dynamic>) {
for (var element in localIt) {
final it = this.it; // To get promotion.
if (it is num) {
yield it;
} else if (it is List<dynamic>) {
for (var element in it) {
yield* TinyJson(element).leaves;
}
} else {
Expand Down