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

Value and type pack runtime crash when used in a method instead of free function #73209

Open
PopFlamingo opened this issue Apr 23, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@PopFlamingo
Copy link

Description

I found a few cases where value and type packs may cause either compiler crashes or executable runtime crashes. This is a simple example where a function has no issue when it is a free function but causes a runtime crash when it is a method.

Reproduction

class Foo {
    init() {}
    func unchanged<each T>(_ value: repeat each T) -> (repeat each T) {
        return (repeat (each value))
    }
}

func unchanged<each T>(_ value: repeat each T) -> (repeat each T) {
    return (repeat (each value))
}

let foo = Foo()


print(unchanged(false, 1, "B")) // Prints (false, 1, "B")
print(foo.unchanged(false, 1, "B")) // RUNTIME ERROR: Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

Stack dump

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000019d562ee4 libswiftCore.dylib`swift::metadataimpl::ValueWitnesses<swift::metadataimpl::NativeBox<unsigned long long, 8ul, 8ul, 8ul>>::initializeWithCopy(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*)
  * frame #1: 0x0000000100001fbc PackBug`Foo.unchanged<each τ_0_0>(value=@indirect Pack{(Swift.Bool, Swift.Int, Swift.String)} @ 0x000000016fdff107, self=0x00006000031c01f0) at main.swift:4:25
    frame #2: 0x0000000100001c38 PackBug`main at main.swift:16:11
    frame #3: 0x000000018d1720e0 dyld`start + 2360

Expected behavior

No crash and printing (false, 1, "B")

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@PopFlamingo PopFlamingo added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Apr 23, 2024
@PopFlamingo PopFlamingo changed the title Value and type pack runtime crash when used as a method instead of free function Value and type pack runtime crash when used in a method instead of free function Apr 23, 2024
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant