Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Tests/PklSwiftTests/Fixtures/Generated/UnionTypes.pkl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension UnionTypes {
case grape(Grape)
case apple(Apple)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -49,7 +49,7 @@ extension UnionTypes {
case zebra(Zebra)
case donkey(Donkey)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -84,7 +84,7 @@ extension UnionTypes {
}
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -119,12 +119,12 @@ extension UnionTypes {
case int(Int)
case float64(Float64)

private static func decodeNumeric(from decoder: Decoder, _ container: any SingleValueDecodingContainer) -> IntOrFloat? {
private static func decodeNumeric(from decoder: any Decoder, _ container: any SingleValueDecodingContainer) -> IntOrFloat? {
return (try? .int(container.decode(Int.self)))
?? (try? .float64(container.decode(Float64.self)))
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let decoded = IntOrFloat.decodeNumeric(from: decoder, container)
if decoded != nil {
Expand Down Expand Up @@ -163,7 +163,7 @@ extension UnionTypes {
}
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -200,14 +200,14 @@ extension UnionTypes {
case int32(Int32)
case int(Int)

private static func decodeNumeric(from decoder: Decoder, _ container: any SingleValueDecodingContainer) -> Numbers? {
private static func decodeNumeric(from decoder: any Decoder, _ container: any SingleValueDecodingContainer) -> Numbers? {
return (try? .int8(container.decode(Int8.self)))
?? (try? .int16(container.decode(Int16.self)))
?? (try? .int32(container.decode(Int32.self)))
?? (try? .int(container.decode(Int.self)))
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let decoded = Numbers.decodeNumeric(from: decoder, container)
if decoded != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension pkl_swift_example_Poly {
}
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -183,7 +183,7 @@ extension pkl_swift_example_Poly {
}
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -349,7 +349,7 @@ extension pkl_swift_example_Poly {
}
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -627,7 +627,7 @@ extension pkl_swift_example_Poly {
}
}

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down Expand Up @@ -854,7 +854,7 @@ extension pkl_swift_example_Poly {
case mappingStringString([String: String])
case mapStringString([String: String])

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down
8 changes: 4 additions & 4 deletions codegen/snippet-tests/output/Enums.pkl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Enums {
case zebra(Zebra)
case monkey(Monkey)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand All @@ -45,7 +45,7 @@ extension Enums {
case mappingStringString([String: String])
case listingString([String])

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand All @@ -70,7 +70,7 @@ extension Enums {
case string(String)
case string(String)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand All @@ -96,7 +96,7 @@ extension Enums {
case optionalHorse(Horse?)
case zebra(Zebra)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let value = try container.decode(PklSwift.PklAny.self).value
switch value?.base {
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/internal/EnumGen.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ local throwTypeMismatch =

local initMethod =
new Listing {
"\(module.indent)public init(from decoder: Decoder) throws {"
"\(module.indent)public init(from decoder: any Decoder) throws {"
"\(module.indent.repeat(2))let container = try decoder.singleValueContainer()"
when (!enumNumericMembers.isEmpty) {
"\(module.indent.repeat(2))let decoded = \(module.mapping.name).decodeNumeric(from: decoder, container)"
Expand Down Expand Up @@ -190,7 +190,7 @@ local synthesizedHash =

local decodeNumeric =
new Listing {
"\(module.indent)private static func decodeNumeric(from decoder: Decoder, _ container: any SingleValueDecodingContainer) -> \(module.mapping.name)? {"
"\(module.indent)private static func decodeNumeric(from decoder: any Decoder, _ container: any SingleValueDecodingContainer) -> \(module.mapping.name)? {"
when (enumNumericMembers.length == 1) {
local member = enumNumericMembers.first
"\(module.indent.repeat(2))return try? .\(member.name)(container.decode(\(member.renderedType).self))"
Expand Down