From d89d9e27e1f3780791d241f797f737a10b59e446 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Mon, 21 Sep 2026 19:43:30 +0200 Subject: [PATCH] Unified: Extract `init` keywords --- unified/extractor/src/languages/swift/swift.rs | 2 ++ .../corpus/swift/types/class-with-initializer.output | 3 ++- .../corpus/swift/types/constructor-with-parameters.output | 3 ++- unified/ql/test/library-tests/controlflow/cfg.expected | 4 ++++ unified/ql/test/library-tests/controlflow/cfg.swift | 8 ++++---- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 8242e37a8a3f..a7253009146d 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -1274,6 +1274,7 @@ fn translation_rules() -> Vec> { // nest under `signature` (as for `functionDecl`). rule!( (initializerDecl + initKeyword: @initK modifiers: _* @mods signature: (functionSignature parameterClause: (functionParameterClause parameters: _* @params)) @@ -1281,6 +1282,7 @@ fn translation_rules() -> Vec> { => (constructor_declaration modifier: {mods} + name_node: (identifier #{initK}) parameter: {params} body: (block stmt: {body_stmts})) ), 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 f5e85a979d67..be9b7be2deb9 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output @@ -98,7 +98,8 @@ top_level source="⟨body⟩" modifier: modifier "var" source="var" pattern: identifier "x" source="x" type: identifier "Int" source="Int" - constructor_declaration source="⟨body⟩⟨parameter⟩" + constructor_declaration source="⟨name_node⟩⟨body⟩⟨parameter⟩" + name_node: identifier "init" source="init" parameter: parameter source="⟨pattern⟩: ⟨type⟩" type: identifier "Int" source="Int" 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 72d8952ea356..82bda546786f 100644 --- a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output +++ b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output @@ -67,7 +67,8 @@ top_level source="⟨body⟩" modifier: modifier "struct" source="struct" name_node: identifier "Size" source="Size" member: - constructor_declaration source="⟨body⟩⟨parameter⟩⟨parameter⟩" + constructor_declaration source="⟨name_node⟩⟨body⟩⟨parameter⟩⟨parameter⟩" + name_node: identifier "init" source="init" parameter: parameter source="⟨external_name_node⟩ ⟨pattern⟩: ⟨type⟩," external_name_node: identifier "width" source="width" diff --git a/unified/ql/test/library-tests/controlflow/cfg.expected b/unified/ql/test/library-tests/controlflow/cfg.expected index fc1f15c91c5f..4024690a7111 100644 --- a/unified/ql/test/library-tests/controlflow/cfg.expected +++ b/unified/ql/test/library-tests/controlflow/cfg.expected @@ -153,7 +153,11 @@ noCfg | cfg.swift:358:6:358:28 | loop_with_identity_expr | | cfg.swift:371:8:371:18 | getOptional | | cfg.swift:380:45:380:47 | Int | +| cfg.swift:391:3:391:6 | init | +| cfg.swift:408:3:408:6 | init | | cfg.swift:421:6:421:22 | localDeclarations | +| cfg.swift:424:5:424:8 | init | +| cfg.swift:431:5:431:8 | init | | cfg.swift:468:6:468:17 | testIfConfig | | cfg.swift:497:6:497:18 | testAvailable | | cfg.swift:524:6:524:17 | testAsyncFor | diff --git a/unified/ql/test/library-tests/controlflow/cfg.swift b/unified/ql/test/library-tests/controlflow/cfg.swift index 2061d46cd78a..e0b598f74fe9 100644 --- a/unified/ql/test/library-tests/controlflow/cfg.swift +++ b/unified/ql/test/library-tests/controlflow/cfg.swift @@ -388,7 +388,7 @@ func testTupleElement(t : (a: Int, Int, c: Int)) -> Int { } class Derived : C { // $ nonSimple='ClassLikeDeclaration -V Derived -^ BaseType -V C' - init() { + init() { // $ noCfg super.init(n: 0) } } @@ -405,7 +405,7 @@ func doWithoutCatch(x : Int) throws -> Int { class Structors { var field: Int - init() { + init() { // $ noCfg field = 10 } @@ -421,14 +421,14 @@ func dictionaryLiteral(x: Int, y: Int) -> [String: Int] { func localDeclarations() -> Int { // $ noCfg class MyLocalClass { var x: Int - init() { + init() { // $ noCfg x = 10 } } struct MyLocalStruct { var x: Int - init() { + init() { // $ noCfg x = 10 } }