Skip to content

Commit 8b12c0c

Browse files
chloestefantsovaCommit Queue
authored and
Commit Queue
committed
[cfe] Desugar BinaryPattern
Part of #49749 Change-Id: I98dd7d63c560eb4c48350c32826e51df1491d9d9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271708 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent c251133 commit 8b12c0c

20 files changed

+899
-91
lines changed

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,19 +2616,32 @@ class BodyBuilder extends StackListenerImpl
26162616
reportIfNotEnabled(
26172617
libraryFeatures.patterns, token.charOffset, token.charCount);
26182618
// ignore: unused_local_variable
2619-
Pattern left = toPattern(pop());
2620-
// ignore: unused_local_variable
26212619
Pattern right = toPattern(pop());
2620+
// ignore: unused_local_variable
2621+
Pattern left = toPattern(pop());
26222622
// TODO(johnniwinther): Create a binary pattern.
26232623

26242624
String operator = token.lexeme;
2625-
BinaryPatternKind kind;
26262625
switch (operator) {
26272626
case '&':
2628-
kind = BinaryPatternKind.and;
2627+
push(new AndPattern(left, right, token.charOffset));
26292628
break;
26302629
case '|':
2631-
kind = BinaryPatternKind.or;
2630+
Map<String, VariableDeclaration> leftVariablesByName = {
2631+
for (VariableDeclaration leftVariable in left.declaredVariables)
2632+
leftVariable.name!: leftVariable
2633+
};
2634+
if (!leftVariablesByName.keys.toSet().containsAll(
2635+
right.declaredVariables.map((variable) => variable.name!)) &&
2636+
leftVariablesByName.length == right.declaredVariables.length) {
2637+
// TODO(cstefantsova): Report a compile-time error.
2638+
}
2639+
push(new OrPattern(left, right, token.charOffset,
2640+
orPatternJointVariables: [
2641+
for (VariableDeclaration leftVariable in left.declaredVariables)
2642+
forest.createVariableDeclaration(
2643+
leftVariable.fileOffset, leftVariable.name)
2644+
]));
26322645
break;
26332646
default:
26342647
internalProblem(
@@ -2637,7 +2650,6 @@ class BodyBuilder extends StackListenerImpl
26372650
token.charOffset,
26382651
uri);
26392652
}
2640-
push(new BinaryPattern(left, kind, right, token.charOffset));
26412653
}
26422654

26432655
void doBinaryExpression(Token token) {

pkg/front_end/lib/src/fasta/kernel/forest.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,11 @@ class Forest {
413413
/// [fileOffset]. The [condition] is the expression preceding the question
414414
/// mark. The [thenExpression] is the expression following the question mark.
415415
/// The [elseExpression] is the expression following the colon.
416-
Expression createConditionalExpression(int fileOffset, Expression condition,
417-
Expression thenExpression, Expression elseExpression) {
416+
ConditionalExpression createConditionalExpression(
417+
int fileOffset,
418+
Expression condition,
419+
Expression thenExpression,
420+
Expression elseExpression) {
418421
return new ConditionalExpression(
419422
condition, thenExpression, elseExpression, const UnknownType())
420423
..fileOffset = fileOffset;

0 commit comments

Comments
 (0)