fix(swift): remove deprecated JSONNull.hashValue#3003
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
quicktype's default Swift output for
JSONNullemitted both thedeprecated
hashValueprotocol requirement andhash(into:):Explicitly implementing
hashValuetriggers the Swift compiler warning'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'JSONNull' to 'Hashable' by implementing 'hash(into:)' instead,since
hashValuewas deprecated as aHashablerequirement in Swift4.2.
A previous PR (#2928 / commit
7a233c5b) madehash(into:)emitunconditionally instead of only under
--swift-5-support, but it didnot remove the old
hashValueproperty, so the deprecation warningremained.
Root cause
packages/quicktype-core/src/language/Swift/SwiftRenderer.tsalwaysemits both
hashValueandhash(into:)forJSONNull(whenobjcSupportis disabled), instead of only the modernhash(into:)requirement.
Fix
Removed the deprecated
hashValuecomputed property and changedhash(into:)'s body from a no-op comment tohasher.combine(0), assuggested in the issue.
Test coverage
test/unit/swift-json-null-hashable.test.tsalready asserted thathash(into:)was emitted, but it didn't assert the deprecatedhashValuewas absent, so it passed even with the bug present.Strengthened it to additionally assert:
hasher.combine(0)is emitted, andpublic var hashValue: Intis 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
JSONNullimplementations 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 "assertingwhat is/isn't generated" case unit tests are for). Existing Swift JSON
and JSON Schema fixture inputs already exercise the
JSONNullcodepath 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).node dist/index.js --lang swift sample.jsonthat the generated
JSONNullno longer containshashValueand thathash(into:)now callshasher.combine(0).swiftcis not installed in this environment, so the Swift fixturesuite (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