Skip to content

fix(swift): extract computed & observed properties (#2181)#2220

Open
ozdemirsarman wants to merge 1 commit into
Graphify-Labs:v8from
ozdemirsarman:fix/swift-computed-properties
Open

fix(swift): extract computed & observed properties (#2181)#2220
ozdemirsarman wants to merge 1 commit into
Graphify-Labs:v8from
ozdemirsarman:fix/swift-computed-properties

Conversation

@ozdemirsarman

Copy link
Copy Markdown

Closes #2181.

Problem

Swift's extractor only treats function_declaration, init_declaration,
deinit_declaration and subscript_declaration as callables
(_SWIFT_CONFIG.function_types). Computed properties parse as
property_declaration → computed_property → statements, which no branch
handled — so they produced no node and their bodies were never walked.

For SwiftUI this is severe: var body: some View { … } is a computed property,
so an entire view file collapses to just the file + struct nodes and every UI
element and call inside body disappears. willSet/didSet observers have the
same shape and lost their body calls too.

Before (repro)

struct PlayerScrubber: View {
    var body: some View { VStack { doTap() } }  // dropped
    var toggled: Int { 1 }                       // dropped
    func doTap() {}                              // extracted
}

Only .doTap() was emitted; body, toggled, and the doTap() call inside
body were all missing.

Fix

In the Swift property_declaration branch (which already collects type-annotation
references), after the existing handling: if the property has a computed_property
or willset_didset_block child, emit a function-like member node (.name,
method edge to the enclosing type) and defer its body to the call-walk via
function_bodies — the same mechanism methods use. This is additive: the
existing references/field edges from the property's type are unchanged.

Stored properties have no body child, so they are untouched (no regression).

After

.body and .toggled are emitted, and the doTap() call inside body now
produces a calls edge from .body.doTap(), so the view hierarchy is
traversed.

Tests

Adds tests/test_swift_computed_properties.py:

  • computed property emits a node and its body is walked (call captured);
  • stored property is not emitted as a member but still yields its type
    references edge (regression guard);
  • willSet/didSet observer body is walked.

Full language test suite (test_languages.py, 324 tests) and the existing Swift
tests pass with no changes.

function_types only recognised func/init/deinit/subscript, so computed properties (var body: some View { ... }) and willSet/didSet observers produced no node and their bodies were never walked — erasing the whole SwiftUI view layer. Emit a function-like member node for them and defer the body to the call-walk via function_bodies; stored properties are unchanged. Adds tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swift: computed properties emit no node — erases the entire SwiftUI view layer (var body is a computed property)

1 participant