mirror of
https://github.com/github/codeql.git
synced 2026-07-31 07:22:56 +02:00
unified: Emit constructor parameters
Emit an initializer's parameters on the `constructor_declaration`, captured from the `initializerDecl` signature (as for `functionDecl`). The tree-sitter path dropped them -- its positional `(parameter)*` capture missed the field-attached parameters -- and the mapping matched that for corpus parity; swift-syntax exposes them cleanly, so emitting them is a correctness improvement. Adds a focused `constructor-with-parameters` corpus case and updates `class-with-initializer` to witness the restored parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1089,18 +1089,18 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
|
||||
// A member of a type declaration unwraps to the contained declaration.
|
||||
rule!((memberBlockItem decl: _* @d) => member* { d }),
|
||||
// Init declaration → constructor_declaration. Body statements optional;
|
||||
// body itself is also optional (protocol requirement).
|
||||
//
|
||||
// PARITY(tree-sitter): the parameters are not emitted, because the
|
||||
// tree-sitter path dropped them (its `(parameter)*` capture missed the
|
||||
// field-attached parameters). Emitting them is a future improvement.
|
||||
// body itself is also optional (protocol requirement). The parameters
|
||||
// nest under `signature` (as for `functionDecl`).
|
||||
rule!(
|
||||
(initializerDecl
|
||||
modifiers: _* @mods
|
||||
signature: (functionSignature
|
||||
parameterClause: (functionParameterClause parameters: _* @params))
|
||||
body: (codeBlock statements: _* @body_stmts)?)
|
||||
=>
|
||||
(constructor_declaration
|
||||
modifier: {mods}
|
||||
parameter: {params}
|
||||
body: (block stmt: {body_stmts}))
|
||||
),
|
||||
// Deinit declaration → destructor_declaration. Body statements optional.
|
||||
|
||||
@@ -103,6 +103,11 @@ top_level
|
||||
named_type_expr
|
||||
name: identifier "Int"
|
||||
constructor_declaration
|
||||
parameter:
|
||||
parameter
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "x"
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
struct Size {
|
||||
init(width w: Int, height h: Int) {}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
structDecl
|
||||
attributes:
|
||||
name: identifier "Size"
|
||||
memberBlock:
|
||||
memberBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
members:
|
||||
memberBlockItem
|
||||
decl:
|
||||
initializerDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
modifiers:
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
functionParameter
|
||||
colon: :
|
||||
attributes:
|
||||
modifiers:
|
||||
trailingComma: ,
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
firstName: identifier "width"
|
||||
secondName: identifier "w"
|
||||
functionParameter
|
||||
colon: :
|
||||
attributes:
|
||||
modifiers:
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
firstName: identifier "height"
|
||||
secondName: identifier "h"
|
||||
initKeyword: init
|
||||
modifiers:
|
||||
structKeyword: struct
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
class_like_declaration
|
||||
modifier: modifier "struct"
|
||||
name: identifier "Size"
|
||||
member:
|
||||
constructor_declaration
|
||||
parameter:
|
||||
parameter
|
||||
external_name: identifier "width"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "w"
|
||||
parameter
|
||||
external_name: identifier "height"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "h"
|
||||
body: block "init(width w: Int, height h: Int) {}"
|
||||
@@ -0,0 +1,3 @@
|
||||
struct Size {
|
||||
init(width w: Int, height h: Int) {}
|
||||
}
|
||||
Reference in New Issue
Block a user