Skip to content

fix(swift): remove deprecated JSONNull.hashValue#3003

Merged
schani merged 1 commit into
masterfrom
agent/fix-issue-1698
Jul 22, 2026
Merged

fix(swift): remove deprecated JSONNull.hashValue#3003
schani merged 1 commit into
masterfrom
agent/fix-issue-1698

Conversation

@schani

@schani schani commented Jul 20, 2026

Copy link
Copy Markdown
Member

Bug

quicktype's default Swift output for JSONNull emitted both the
deprecated hashValue protocol requirement and hash(into:):

class JSONNull: Codable, Hashable {
    public static func == (lhs: JSONNull, rhs: JSONNull) -> Bool {
        return true
    }

    public var hashValue: Int {
        return 0
    }

    public func hash(into hasher: inout Hasher) {
        // No-op
    }
    ...
}

Explicitly implementing hashValue triggers the Swift compiler warning
'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'JSONNull' to 'Hashable' by implementing 'hash(into:)' instead,
since hashValue was deprecated as a Hashable requirement in Swift
4.2.

A previous PR (#2928 / commit 7a233c5b) made hash(into:) emit
unconditionally instead of only under --swift-5-support, but it did
not remove the old hashValue property, so the deprecation warning
remained.

Root cause

packages/quicktype-core/src/language/Swift/SwiftRenderer.ts always
emits both hashValue and hash(into:) for JSONNull (when
objcSupport is disabled), instead of only the modern hash(into:)
requirement.

Fix

Removed the deprecated hashValue computed property and changed
hash(into:)'s body from a no-op comment to hasher.combine(0), as
suggested in the issue.

Test coverage

test/unit/swift-json-null-hashable.test.ts already asserted that
hash(into:) was emitted, but it didn't assert the deprecated
hashValue was absent, so it passed even with the bug present.
Strengthened it to additionally assert:

  • hasher.combine(0) is emitted, and
  • public var hashValue: Int is not emitted.

I verified this test fails against the pre-fix renderer and passes
after the fix. This is a unit test rather than a fixture test because
the Swift fixture harness only compiles the generated code and
round-trips JSON through it — both the buggy and fixed JSONNull
implementations compile and behave identically at runtime, so a
fixture round-trip cannot distinguish them; only the generated source
text differs (per CLAUDE.md, this is exactly the kind of "asserting
what is/isn't generated" case unit tests are for). Existing Swift JSON
and JSON Schema fixture inputs already exercise the JSONNull
codepath through nullable values, so fixture coverage for the
surrounding code is unaffected.

Verification

  • npm run build — passes.
  • npx vitest run test/unit/swift-json-null-hashable.test.ts test/unit/swift-final-classes.test.ts — passes (4/4).
  • Manually confirmed with node dist/index.js --lang swift sample.json
    that the generated JSONNull no longer contains hashValue and that
    hash(into:) now calls hasher.combine(0).
  • swiftc is not installed in this environment, so the Swift fixture
    suite (which compiles and runs the generated code) could not be run
    locally; CI will validate actual Swift compilation of the fixture
    inputs.

Fixes #1698

🤖 Generated with Claude Code

Swift's default JSONNull class emitted both the deprecated `hashValue`
protocol requirement and `hash(into:)`, triggering a
'Hashable.hashValue is deprecated as a protocol requirement' compiler
warning. Remove the redundant `hashValue` property and have
`hash(into:)` call `hasher.combine(0)` as suggested in the issue.

Adds/strengthens a unit test asserting the deprecated property is no
longer emitted and that hash(into:) uses hasher.combine(0).

Fixes #1698

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

'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'JSONNull' to 'Hashable' by implementing 'hash(into:)' instead

1 participant