From ed60aa350355eb8d405b7b4b92e412f54adef830 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Mon, 20 Jul 2026 17:18:20 -0400 Subject: [PATCH] fix(swift): remove deprecated JSONNull.hashValue (#1698) 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 --- .../quicktype-core/src/language/Swift/SwiftRenderer.ts | 7 +------ test/unit/swift-json-null-hashable.test.ts | 4 +++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts b/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts index a47b189df1..71d3b103b6 100644 --- a/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts +++ b/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts @@ -1183,14 +1183,9 @@ encoder.dateEncodingStrategy = .formatted(formatter)`); }`); if (this._options.objcSupport === false) { - this.ensureBlankLine(); - this.emitMultiline(` public var hashValue: Int { - return 0 - }`); - this.ensureBlankLine(); this.emitMultiline(` public func hash(into hasher: inout Hasher) { - // No-op + hasher.combine(0) }`); } diff --git a/test/unit/swift-json-null-hashable.test.ts b/test/unit/swift-json-null-hashable.test.ts index 78c9cf9288..d8013b9df3 100644 --- a/test/unit/swift-json-null-hashable.test.ts +++ b/test/unit/swift-json-null-hashable.test.ts @@ -13,7 +13,7 @@ const schema = JSON.stringify({ required: ["value"], }); -test("emits hash(into:) for JSONNull by default", async () => { +test("emits modern Hashable implementation for JSONNull by default", async () => { const schemaInput = new JSONSchemaInput(undefined); await schemaInput.addSource({ name: "TopLevel", schema }); @@ -24,4 +24,6 @@ test("emits hash(into:) for JSONNull by default", async () => { const output = result.lines.join("\n"); expect(output).toContain("public func hash(into hasher: inout Hasher)"); + expect(output).toContain("hasher.combine(0)"); + expect(output).not.toContain("public var hashValue: Int"); });