Skip to content

Commit aeca3cf

Browse files
committed
Unified: Translate callee in non-pattern context also for calls with
trailing closure Previously the callee was handled differently depending on whether the call had a trailing closure. This merges the two rules for `functionCallExpr` into one to erase the difference.
1 parent b1681b0 commit aeca3cf

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -704,23 +704,25 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
704704
),
705705
// A function/method call (`foo(1, 2)`). `calledExpression` is the callee
706706
// and `arguments` is an (elided) list of `labeledExpr`, each translated
707-
// to an `argument` below. A trailing closure (`xs.map { … }`) becomes a
708-
// final unlabelled argument; that variant is matched first.
707+
// to an `argument` below. A trailing closure (`xs.map { … }`) becomes
708+
// a final unlabelled argument.
709709
rule!(
710-
(functionCallExpr calledExpression: @callee arguments: _* @args trailingClosure: @tc)
711-
=>
712-
(call_expr callee: {callee} argument: {args} argument: (argument value: {tc}))
713-
),
714-
rule!(
715-
(functionCallExpr calledExpression: @@rawCallee arguments: _* @args)
710+
(functionCallExpr
711+
calledExpression: @@rawCallee
712+
arguments: _* @args
713+
trailingClosure: _? @trailing)
716714
=>
717715
expr {
718716
// Always translate the callee in non-pattern context.
719717
let callee = ctx.scoped(|ctx| {
720718
ctx.in_pattern = false;
721719
ctx.translate(rawCallee)
722720
})?;
723-
tree!((call_expr callee: {callee} argument: {args}))
721+
tree!((call_expr
722+
callee: {callee}
723+
argument: {args}
724+
argument: {trailing.map(|trailing| tree!((argument value: {trailing})))}
725+
))
724726
}
725727
),
726728
// A call or enum-case pattern argument.

‎unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,8 @@ top_level source="⟨body⟩"
269269
pattern:
270270
call_expr source="⟨callee⟩ ⟨argument⟩"
271271
callee:
272-
member_access_expr source="⟨base⟩.⟨member_name_node⟩"
273-
base:
274-
call_expr source="⟨argument⟩?"
275-
callee:
276-
member_access_expr source=""
277-
base: identifier "Optional" source=""
278-
member_name_node: identifier "some" source=""
279-
argument:
280-
argument source="⟨value⟩"
281-
value: identifier "values" source="values"
272+
member_access_expr source="⟨base⟩?.⟨member_name_node⟩"
273+
base: identifier "values" source="values"
282274
member_name_node: identifier "map" source="map"
283275
argument:
284276
argument source="⟨value⟩"

0 commit comments

Comments
 (0)