Skip to content

Commit 1a6b292

Browse files
committed
fix(swift): retain Sendable alias parameters in selectors
Signed-off-by: DavidHLP <[email protected]>
1 parent ff4b1eb commit 1a6b292

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎internal/cbm/callable_sig.c‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,27 @@ static TSNode sig_swift_selector_type(const sig_ctx_t *c, TSNode parameter, TSNo
786786
return type;
787787
}
788788

789+
static void sig_swift_alias_parameters(sig_ctx_t *c, TSNode function) {
790+
TSNode first = ts_node_child(function, 0);
791+
if (ts_node_is_null(first) || !sig_node_text_is(c, first, "throws")) {
792+
return;
793+
}
794+
/* The Swift grammar can attach the parameter tuple to @Sendable before throws. */
795+
TSNode modifiers = ts_node_prev_named_sibling(function);
796+
if (ts_node_is_null(modifiers) || strcmp(ts_node_type(modifiers), "type_modifiers") != 0) {
797+
return;
798+
}
799+
TSNode attribute = cbm_find_child_by_kind(modifiers, "attribute");
800+
if (ts_node_is_null(attribute) || ts_node_child_count(attribute) < 4 ||
801+
!sig_node_text_is(c, ts_node_named_child(attribute, 0), "Sendable") ||
802+
!sig_node_text_is(c, ts_node_child(attribute, 2), "(")) {
803+
return;
804+
}
805+
for (uint32_t i = 2; i < ts_node_child_count(attribute); i++) {
806+
sig_type_tokens(c, ts_node_child(attribute, i));
807+
}
808+
}
809+
789810
static void sig_swift_param_type(sig_ctx_t *c, TSNode p, TSNode internal) {
790811
size_t before = c->len;
791812
uint32_t count = ts_node_child_count(p);
@@ -813,7 +834,11 @@ static void sig_swift_param_type(sig_ctx_t *c, TSNode p, TSNode internal) {
813834
}
814835
}
815836
} else if (ts_node_is_named(ch)) {
816-
sig_type_tokens(c, sig_swift_selector_type(c, p, ch));
837+
TSNode type = sig_swift_selector_type(c, p, ch);
838+
if (!ts_node_eq(type, ch)) {
839+
sig_swift_alias_parameters(c, type);
840+
}
841+
sig_type_tokens(c, type);
817842
} else if (sig_node_text_is(c, ch, "...")) {
818843
sig_raw_str(c, sig_variadic_marker(c->lang));
819844
}

0 commit comments

Comments
 (0)