Skip to content

Commit

Permalink
[parser] Add missing handling of null-aware elements in if-else
Browse files Browse the repository at this point in the history
Part of #55954

Change-Id: Ie22ff9ddf50f47e20b1cfbf11f01bdc900123619
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388003
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Chloe Stefantsova <[email protected]>
  • Loading branch information
chloestefantsova authored and Commit Queue committed Oct 7, 2024
1 parent 3b8eca8 commit 06223ff
Show file tree
Hide file tree
Showing 6 changed files with 4,175 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class IfElse extends LiteralEntryInfo {
return new Nested(ifCondition, const IfElseComplete());
} else if (optional('...', next) || optional('...?', next)) {
return const ElseSpread();
} else if (optional('?', next)) {
return new Nested(nullAwareEntry, const IfElseComplete());
}
return const ElseEntry();
}
Expand Down
110 changes: 110 additions & 0 deletions pkg/front_end/parser_testcases/null_aware_elements/nested.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
test1(List list, bool Function(dynamic) p, int? a) {
return {
for (var element in list)
if (p(element))
?a
};
}

test2(List list, bool Function(dynamic) p, int? a, int? b) {
return {
for (var element in list)
if (p(element))
?a
else
?b
};
}

test3(List list, bool t, int? a) {
return {
if (t)
for (var element in list)
?a
};
}

test4(List list, bool t, int? a, int? b) {
return {
if (t)
for (var element in list)
?a
else
for (var element in list)
?b
};
}

test5(List list, bool Function(dynamic) p, int? a) {
return {
for (var element in list)
if (p(element))
?a: "value"
};
}

test6(List list, bool Function(dynamic) p, int? a, int? b) {
return {
for (var element in list)
if (p(element))
?a: "value"
else
?b: "value"
};
}

test7(List list, bool t, int? a) {
return {
if (t)
for (var element in list)
?a: "value"
};
}

test8(List list, bool t, int? a, int? b) {
return {
if (t)
for (var element in list)
?a: "value"
else
for (var element in list)
?b: "value"
};
}

test9(List list, bool Function(dynamic) p, int? a) {
return {
for (var element in list)
if (p(element))
"key": ?a
};
}

test10(List list, bool Function(dynamic) p, int? a, int? b) {
return {
for (var element in list)
if (p(element))
"key": ?a
else
"key": ?b
};
}

test11(List list, bool t, int? a) {
return {
if (t)
for (var element in list)
"key": ?a
};
}

test12(List list, bool t, int? a, int? b) {
return {
if (t)
for (var element in list)
"key": ?a
else
for (var element in list)
"key": ?b
};
}
Loading

0 comments on commit 06223ff

Please sign in to comment.