From 3f56bc7d5e803f99236ed2976cf7ab33dd704dda Mon Sep 17 00:00:00 2001 From: Taus Date: Thu, 23 Jul 2026 13:05:28 +0000 Subject: [PATCH] unified: Emit function and initializer parameter types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Emit a parameter's declared type on the mapped `parameter` node. The tree-sitter path dropped it — its untyped-parameter rule was ordered before the typed one and shadowed it — and the mapping matched that for corpus parity; swift-syntax models the type as a required `functionParameter.type`, so emitting it is a correctness improvement. The existing function-parameter corpus cases (and the initializer cases from the previous commit) witness the restored types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- unified/extractor/src/languages/swift/swift.rs | 11 ++++------- .../function-with-default-parameter-value.output | 3 +++ .../functions/function-with-named-parameters.output | 3 +++ .../function-with-parameters-and-return-type.output | 6 ++++++ .../corpus/swift/functions/generic-function.output | 3 +++ .../corpus/swift/functions/variadic-function.output | 3 +++ .../corpus/swift/types/class-with-initializer.output | 3 +++ .../swift/types/constructor-with-parameters.output | 6 ++++++ 8 files changed, 31 insertions(+), 7 deletions(-) diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 6066e411cec..77b3d1e6dec 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -560,17 +560,13 @@ fn translation_rules() -> Vec> { ), // A function parameter. With two names (`firstName`+`secondName`) the // first is the external argument label and the second the internal name; - // with one name it is just the internal name. The default value is - // optional. - // - // PARITY: the declared type is intentionally dropped. In the tree-sitter - // path the untyped-parameter rule was ordered before the typed one and - // shadowed it (first match wins), so the baseline emits no parameter - // type; emitting one here would diverge from it. + // with one name it is just the internal name. The declared type is + // emitted; the default value is optional. rule!( (functionParameter firstName: @@first secondName: _? @@second + type: @ty defaultValue: (initializerClause value: @val)?) => parameter { @@ -581,6 +577,7 @@ fn translation_rules() -> Vec> { tree!((parameter external_name: {external} pattern: (name_pattern identifier: (identifier #{name})) + type: {ty} default: {val})) } ), diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output index 01c0ddef856..3495a13106f 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output @@ -69,6 +69,9 @@ top_level name: identifier "greet" parameter: parameter + type: + named_type_expr + name: identifier "String" pattern: name_pattern identifier: identifier "name" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output index f2024b47362..7488edbcb23 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output @@ -61,6 +61,9 @@ top_level parameter: parameter external_name: identifier "person" + type: + named_type_expr + name: identifier "String" pattern: name_pattern identifier: identifier "name" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output index 1ffb391dbc5..e69b1930767 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output @@ -78,11 +78,17 @@ top_level parameter: parameter external_name: identifier "_" + type: + named_type_expr + name: identifier "Int" pattern: name_pattern identifier: identifier "a" parameter external_name: identifier "_" + type: + named_type_expr + name: identifier "Int" pattern: name_pattern identifier: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/functions/generic-function.output b/unified/extractor/tests/corpus/swift/functions/generic-function.output index 1652f7f4741..d09aac2744a 100644 --- a/unified/extractor/tests/corpus/swift/functions/generic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/generic-function.output @@ -68,6 +68,9 @@ top_level parameter: parameter external_name: identifier "_" + type: + named_type_expr + name: identifier "T" pattern: name_pattern identifier: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/functions/variadic-function.output b/unified/extractor/tests/corpus/swift/functions/variadic-function.output index 571f07c35e0..78c20ffc01e 100644 --- a/unified/extractor/tests/corpus/swift/functions/variadic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/variadic-function.output @@ -82,6 +82,9 @@ top_level parameter: parameter external_name: identifier "_" + type: + named_type_expr + name: identifier "Int" pattern: name_pattern identifier: identifier "values" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output index 32f94417d66..83945d89e3a 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output @@ -105,6 +105,9 @@ top_level constructor_declaration parameter: parameter + type: + named_type_expr + name: identifier "Int" pattern: name_pattern identifier: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output index c26d04b6ce0..c9be21dd156 100644 --- a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output +++ b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output @@ -71,11 +71,17 @@ top_level parameter: parameter external_name: identifier "width" + type: + named_type_expr + name: identifier "Int" pattern: name_pattern identifier: identifier "w" parameter external_name: identifier "height" + type: + named_type_expr + name: identifier "Int" pattern: name_pattern identifier: identifier "h"