Skip to content

Conversation

@danwood
Copy link
Contributor

@danwood danwood commented Jan 29, 2026

This is a fix to issue #1062 : Follow property type references from child declarations when marking

Root cause

Swift's indexer associates property type references (the type annotation on a var or let) with the property declaration itself, not with the enclosing type. UsedDeclarationMarker.markUsed() only walked declaration.references and declaration.related -- it never descended into child declarations. This meant that when a type was marked as used, types referenced only as property types of its child variable declarations were never discovered.

What changed

markUsed() now iterates over child declarations of each used declaration, filtered to variable-kind children only. For each child variable, it follows references that have the .varType role. This causes the referenced types to be marked as used transitively.

The .varType filter is important: without it, following all references from child variables would over-retain sibling properties that reference each other (e.g., a lazy var referencing a private stored property). By restricting to type references only, the fix targets the specific gap without changing retention behavior for value references between properties.

Test changes

  • An existing test expectation was corrected: a class used as a property type on an unused instance variable is now expected to be retained (it was previously expected to be unreferenced, which was incorrect -- removing the class would break compilation).
  • A new test case validates the nested-struct scenario directly, confirming that a type referenced only as a property type inside a nested child struct is retained when the parent type is used.

@danwood
Copy link
Contributor Author

danwood commented Jan 29, 2026

@ileitch Any idea why the lint CI task is failing?

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.

1 participant