Skip to content

Unboxing fails without 2nd unboxing #65282

Open
@jasonbobier

Description

@jasonbobier

I have a bizarre unboxing issue in my test cases. If I make a call to wtf() below, everything compiles and the test runs correctly. If I comment out wtf() I get a Type 'any Unit' (aka 'any Unit') cannot conform to 'Unit'.

static var testValues: [(unit: any Unit, abbreviated: String, narrow: String, wide: String)] {
	[
		(EnergyUnit.kilowattHours, "kW·hs", "kWh", "kilowatt-hours"),
	]
}

func test_formatted__Unit_FormatStyle() {
	func test(unit: some Unit, abbreviated: String, narrow: String, wide: String) {
		XCTAssertEqual(unit.formatted(.unit(width: .abbreviated, locale: locale)), abbreviated)
		XCTAssertEqual(unit.formatted(.unit(width: .narrow, locale: locale)), narrow)
		XCTAssertEqual(unit.formatted(.unit(width: .wide, locale: locale)), wide)
	}

	func wtf(unit: some Unit) {
	}

	// Returns a properly formatted string
	Self.testValues.forEach {
		wtf(unit: $0.unit) // comment this out and the code fails to compile

		test(unit: $0.unit, abbreviated: $0.abbreviated, narrow: $0.narrow, wide: $0.wide)
	}
}

Environment
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)

Xcode 14.3
Build version 14E222b

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.closuresFeature: closurescompilerThe Swift compiler itselfexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeswift 6.0tuplesFeature: tuplestype checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions