Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker and Compiler errors when destructuring Parameter Pack return tuple #79016

Open
bobspryn opened this issue Jan 29, 2025 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@bobspryn
Copy link

Description

I'm getting either linker errors, or sometimes compiler errors (depending on the exact approach) when trying to access destructured Parameter Pack tuples. I'm imagining this is related to one of the existing filed bugs, but it's not obvious to me.

Reproduction

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 linker 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
	}
}

If I move my method into an extension ONLY on QueryStateAccessing, then the compiler is happy

extension QueryStateAccessing {
    func values<each T: QueryResponseProtocol>(for types: repeat (each T).Type) throws -> (repeat each T) {
        fatalError() // since I wouldn't actually have my implementation here
    }
}

or if I use a method without metatypes in an extension and access my underlying method, then the compiler is happy

extension QueryStateAccessing {
  func values<each Response: QueryResponseProtocol>() throws -> (repeat each Response) {
    try values(for: repeat (each Response).self)
  }
}

// usage

let (pricingResponse, aspectsResponse): (PricingResponse, AspectsResponse)
    = try queryState.values()
_ = pricingResponse.price
_ = aspectsResponse.aspects

Expected behavior

Compiles normally.

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
also tried with
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)

Additional information

No response

@bobspryn bobspryn added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant