swift: #expect crashes with EXC_BAD_ACCESS when condition comparing generics is false

Description

Hello, i found a strange issue while playing around with the testing library.

I will provide some more context later, but the reproduction is very simple: compare two objects in #expect, if the condition is false there is a crash, if the condition is true everything is ok.

I made a test with various samples but the ones causing an issue seem to be related to enums with generic. In the reproduction examples below the difference is that .playerStandUp are enums without generics and it works, and .roundEnded is an enum with generics and it fails.

That’s the only difference that i see for now.

Expected behavior

Test fails providing some details about unfulfilled expectation

Actual behavior

Test crashes with a EXC_BAD_ACCESS (code=1, address=0x10)

Steps to reproduce

Run the test in the latest xcode

@Test("Why are you crashing")
		func whyAreYouCrashing() async throws {
			#expect(.roundEnded(
				board: GenericBoard,
				winningSides: [Blacks],
				reason:.agreedDraw
			) == .roundEnded(
				board: GenericBoard,
				winningSides: [Blacks],
				reason:.abandon
			))
		}

But this one works (failed expectation as it should be)

@Test("Why do you work then")
		func whyDoYouWorkThen() async throws {
			#expect(.playerStandUp(
				attendees: Attendees(
					players: [:],
					observers: []
				),
				playerId: "id-wrong",
				side: Whites
			) == .playerStandUp(
				attendees: Attendees(
					players: [:],
					observers: []
				),
				playerId: "id-correct",
				side: Whites
			))
			
		}

swift-testing version/commit hash

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Do you know if that fix already shipped in the latest Swift version?

I don’t believe that fix has shipped in any release yet. I can look into pulling it in to an earlier Swift release.

@nmdias Thank you — yes, that crash log helps confirm that this is a different issue. I believe this may have been fixed by https://github.com/swiftlang/swift-testing/pull/787

(As an aside: that crash log file is quite lengthy. Any chance you could edit your comment so that the log is a file attachment instead? Just to avoid distracting from this ongoing issue. Thanks!)

We’re trying to get the name for a tuple type. That requires getting the name for all the elements. That failed for one of the elements, and the code doesn’t tolerate failure and crashes.

This may actually be fixed by my change here: https://github.com/swiftlang/swift/pull/71664. But that doesn’t help you on macOS 14.

Maybe this info will help you narrow down the troublesome type. If you have tuples in here somewhere (I think enum associated types with more than one value are implicitly represented with tuples), you can try removing or changing them one by one until you find the one that causes the issue. Even with my fix above, it seems likely that there’s another problem in here, since we should probably be able to generate this name, and my fix just makes it fail more gracefully.