Compiler errors destructuring Parameter Pack return tuple

Ok, I'm stumped here. Am I holding this wrong somehow? I get compiler errors, or undefined symbol errors, when trying to access destructured tuples returned from using a parameter pack function. Simple repro below:

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

		// compiler happy when use the ResponseTuple type approach
		// let responseTuple = try queryState.values(for: PricingResponse.self, AspectsResponse.self)
		// _ = responseTuple.responses.1
	}
}
1 Like

Even trying those workarounds I still get a compiler error.

Thanks for confirming! This is unfortunate after 2 years of releases.

Correction, it does work if I do it in an extension like you did. But not if I just put that method in the main protocol.

1 Like

Yeah, weird. I have to add your method without metatypes in an extension, and can't add the signature in the protocol, or else I get an error.

I'm using Xcode 16.1(16B40) and also tested in 16.2.

1 Like

lolol, in fact, if I add MY method in an extension instead of the protocol, it also works!

1 Like

Gah. So close. I'm trying to solve for this last detractor in my design where I have to list my dependencies in an array separately for registering the request, but when pulling the values I need to use parameter packs. Trying to leverage a separate Parameter Packs container, but it fails compiling with:

"unsafeMutableAddressor of aspectsResponse #1 : QueryMaestroPOC.AspectsResponse in QueryMaestroPOC.ShippingServiceRequest.init(listing: QueryMaestroPOC.ListingModel, queryState: QueryMaestroPOC.QueryStateAccessing) throws -> QueryMaestroPOC.ShippingServiceRequest"
/// A type that encapsulates a parameter pack of query response types
/// Used to define dependencies once and reuse them for both registration and value retrieval
struct DependenciesContainer<each T: QueryResponseProtocol> {
	/// Create a dependencies collection
	init() {}
}

struct ShippingServiceRequest: OrchestrationServiceRequestProtocol {
	typealias ResponseModel = ShippingResponse

	/// Define dependencies once
    typealias DependencyCollection = DependenciesContainer<PricingResponse, AspectsResponse>

	/// Use the dependencies collection for registration
    static let dependencies: [any QueryResponseProtocol.Type] = [
        AspectsResponse.self,
        PricingResponse.self,
    ]
    
	init(listing: ListingModel, queryState: QueryStateAccessing) throws {
		let postalCode = try listing.require(keyPaths: \.postalCode)

		// Use the same dependencies collection to retrieve values
        let (pricingResponse, aspectsResponse) = try queryState.values(dependencies: DependencyCollection.self)

		self.postalCode = postalCode
		price = pricingResponse.price
		aspects = aspectsResponse.aspects
		title = listing.title
	}

	let postalCode: String
	let price: Decimal
	let aspects: [String]
	let title: String
}

struct ShippingResponse: QueryResponseProtocol {
	let services: [String]
	typealias Request = ShippingServiceRequest
}

extension ShippingResponse {
	init() {
		services = []
	}
}