swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.32k stars 10.34k forks source link

#expect crashes with EXC_BAD_ACCESS when condition comparing generics is false #76608

Open master-bytes-krafter opened 5 hours ago

master-bytes-krafter commented 5 hours ago

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

master-bytes-krafter commented 3 hours ago

Hmm i was trying to produce an easily reproductible sample but without success for now, i will keep trying. The code that fails (looking at the trace) fails somewhere here

#0  0x00000001a68b8000 in _swift_buildDemanglingForMetadata ()

swiftlang/swift-testing#21  0x000000010338c3a8 in Testing.__checkBinaryOperation<τ_0_0, τ_0_1>(_: τ_0_0, _: (τ_0_0, () -> τ_0_1) -> Swift.Bool, _: @autoclosure () -> τ_0_1, expression: Testing.__Expression, comments: @autoclosure () -> Swift.Array<Testing.Comment>, isRequired: Swift.Bool, sourceLocation: Testing.SourceLocation) -> Swift.Result<(), Swift.Error> ()

For now it is not blocking as tests should pass anyway but it could make tracking any bug a little bit harder

grynspan commented 3 hours ago

Looks like a runtime crash. Forwarding to the runtime team to triage.