Skip to content

fix(closures): make callback captures explicit - #1267

Draft
cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:fix/explicit-closure-captures
Draft

cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:fix/explicit-closure-captures

Conversation

@cristim

@cristim cristim commented Nov 24, 2026

Copy link
Copy Markdown

Summary

Two escaping callbacks capture state implicitly. This makes both captures explicit:

  • AccessibilityLinkRotorBridge.update() writes self.elements inside the enumerateAttribute callback.
  • DynamicTextHelper.widthAdaptedText reads the sizeVariant property inside the enumerateAttribute callback; it now reads it once into a local before the callback.

Why

With a Foundation whose enumerateAttribute/enumerateAttributes callback is @escaping (the Foundation used by our Darling work, not Apple's), the unchanged code produces the implicit-self diagnostic in the rotor and the mutating-self capture diagnostic in the lazy var of a struct. Apple's Foundation declares the callback non-escaping, so behaviour there is unchanged. The change has no effect on behaviour: the same values are used, they are just named or read earlier.

Provenance

Local commit from 2026-10-15 (Cristian Magherusan-Stanciu), originally two commits on 2026-10-13 combined into one. It applies to current main without changes; I reworded the message.

Testing

Not compiled with this repo's package build, and no tests run: no Swift toolchain is available on the machine where I prepared this port. The original author reported, for the original commit, reduced-source red/green checks with Swift 6.3.3 (the unchanged expressions reproduce the diagnostics, the changed ones emit SIL without them). The complete OpenSwiftUI package, link and runtime were not verified then either. No test was added: the change has no runtime-visible effect on Apple platforms.

🤖 Generated with Claude Code

Qualify the rotor's captured `elements` access and snapshot the text size
variant before the escaping Foundation callback. This removes the implicit-
self and mutating-self diagnostics when the Foundation callback is escaping.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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