Skip to content

fix(swift): allow Sendable conformance with objective-c-support#3017

Merged
schani merged 1 commit into
masterfrom
agent/fix-issue-2781
Jul 21, 2026
Merged

fix(swift): allow Sendable conformance with objective-c-support#3017
schani merged 1 commit into
masterfrom
agent/fix-issue-2781

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

With --sendable --objective-c-support, generated Swift types lost Sendable conformance entirely — even enums, which have no NSObject/Objective-C interop concern at all.

Repro (from issue #2781, using the maintainer triage's schema/flags):

node dist/index.js --lang swift --src-lang schema --src example.schema.json \
  --sendable --struct-or-class class --objective-c-support --top-level Example

Before: @objcMembers class Example: NSObject, Codable { ... } and enum Fruit: String, Codable { ... } — zero occurrences of Sendable.

Without --objective-c-support, the same input correctly produced class Example: Codable, Sendable and enum Fruit: String, Codable, Sendable.

Root cause

getProtocolsArray in packages/quicktype-core/src/language/Swift/SwiftRenderer.ts unconditionally dropped Sendable whenever objcSupport was enabled, regardless of declaration kind (class/struct/enum). Enums and structs have no NSObject interop concern, so the guard was over-broad. For classes, Swift does allow Sendable conformance on an NSObject subclass provided the class is final and has only immutable, Sendable stored properties.

Fix

  • Dropped the blanket !this._options.objcSupport guard in getProtocolsArray, so Sendable is added whenever --sendable is set and (for classes) properties are immutable — independent of objcSupport.
  • When emitting a class declaration, also emit final whenever sendable is on and properties are immutable (in addition to the existing finalClasses option), since Swift requires NSObject subclasses to be final to conform to Sendable.
  • Classes with --mutable-properties remain non-Sendable/non-final, matching existing (correct) behavior without --objective-c-support.

Test coverage

Added a new fixture, swift-sendable-objective-c (test/languages.ts / test/fixtures.ts), that generates Swift with --sendable --struct-or-class class --objective-c-support (plus a struct-or-class: struct variant via quickTestRendererOptions) and runs a small verification script (test/fixtures/swift/verify-sendable.cjs) asserting every generated class/struct/enum declaration includes Sendable, and that Sendable classes are emitted @objcMembers final class.

Real swiftc compilation isn't available in this environment (and the existing swift/schema-swift fixtures are already disabled in CI's test-pr.yaml due to a pre-existing "pgp issue"), so this fixture verifies the generated source text directly rather than compiling/running it, following the same includeJSON/custom-compileCommand pattern already used elsewhere in test/languages.ts (e.g. the nbl-stats.json-scoped fixtures).

Verification performed locally

  • Confirmed the new fixture fails (exit 1, Generated type is not Sendable) against the pre-fix renderer, and passes after the fix.
  • QUICKTEST=true FIXTURE=swift-sendable-objective-c script/test passes.
  • npm run test:unit — 169/169 tests pass.
  • npm run lint (biome) — clean.
  • npm run build — passes.
  • Manually re-ran the issue's repro command and confirmed correct output for class+immutable, class+mutable-properties, and struct cases.

Fixes #2781

🤖 Generated with Claude Code

getProtocolsArray unconditionally dropped Sendable whenever objcSupport
was enabled, even for enums and structs that have no NSObject/objc
interop concern. Drop that guard, and for classes emit `final` (Swift
requires NSObject subclasses to be final and immutable to be Sendable)
whenever sendable is on and properties are immutable.

Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
@schani
schani merged commit cac8f32 into master Jul 21, 2026
28 checks passed
@schani
schani deleted the agent/fix-issue-2781 branch July 21, 2026 13:35
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.

[BUG]: Objective-C compatible Swift does not get Sendable conformance

1 participant