Last active
January 29, 2025 06:34
-
-
Save bobspryn/31f1dd636ef7e04e5198b81096c01d7f to your computer and use it in GitHub Desktop.
Compiler errors with Parameter Packs
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
import Foundation | |
struct ResponseTuple<each Response: QueryResponseProtocol> { | |
let responses: (repeat each Response) | |
} | |
protocol QueryResponseProtocol: Equatable {} | |
protocol QueryStateAccessing { | |
func values<each T: QueryResponseProtocol>(for types: repeat (each T).Type) throws -> (repeat each T) | |
// If I instead use a ResponseTuple type for the return, then the compiler is happy when I access the properties | |
// func values<each T: QueryResponseProtocol>(for types: repeat (each T).Type) throws -> ResponseTuple<repeat each T> | |
} | |
struct ShippingResponse: QueryResponseProtocol { | |
let service: String | |
} | |
struct AspectsResponse: QueryResponseProtocol { | |
let aspects: [String] | |
} | |
struct PricingResponse: QueryResponseProtocol { | |
let price: Decimal | |
} | |
struct ShippingServiceRequest { | |
typealias ResponseModel = ShippingResponse | |
init(queryState: QueryStateAccessing) throws { | |
let (pricingResponse, aspectsResponse) = try queryState.values(for: PricingResponse.self, AspectsResponse.self) | |
_ = pricingResponse.price // this works fine | |
// _ = aspectsResponse.aspects // this is a compiler error - Undefined symbol | |
// single value is a compiler error | |
// let (pricingResponse) = try queryState.values(for: PricingResponse.self) // this is a compiler error | |
// this is a compiler error | |
// let results = try queryState.values(for: PricingResponse.self, AspectsResponse.self) | |
// _ = results.0 | |
// happy to use the ResponseTuple type | |
// let responseTuple = try queryState.values(for: PricingResponse.self, AspectsResponse.self) | |
// _ = responseTuple.responses.1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment