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

Using P.self on private @objc protocol with custom ObjC name causing crash. #74546

Open
WeZZard opened this issue Jun 19, 2024 · 1 comment
Open
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 @objc Feature → attributes: The @objc attribute objective-c interop Feature: Interoperability with Objective-C protocol Feature → type declarations: Protocol declarations runtime The Swift Runtime swift 6.0

Comments

@WeZZard
Copy link
Contributor

WeZZard commented Jun 19, 2024

Description

Running the following code on Xcode 15.0 and 16.0 causing a runtime crash. a can be evaluated in LLDB. However, it's 0x0 when evaluated in assembly mode.

@objc(MyName)
private protocol MyObjCProtocol {
    
    func myObjCProtocolMessage()
    
}

private let a = MyObjCProtocol.self
print(a)
Screenshot 2024-06-19 at 18 11 02 Screenshot 2024-06-19 at 18 11 36

Reproduction

@objc(MyName)
private protocol MyObjCProtocol {
    
    func myObjCProtocolMessage()
    
}

private let a = MyObjCProtocol.self
print(a)

Stack dump

Thread 1 Queue : com.apple.main-thread (serial)
#0	0x00000001acad98d0 in outlined init with copy of Any ()
#1	0x00000001ac932d5c in specialized _print<τ_0_0>(_:separator:terminator:to:) ()
#2	0x00000001ac931efc in print(_:separator:terminator:) ()
#3	0x00000001000032dc in main at main.swift:295
#4	0x000000019c73e0e0 in start ()

Expected behavior

Printing "MyObjCProtocol"

Environment

Xcode 15.0
Xcode 16.0

Additional information

No response

@WeZZard WeZZard 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 Jun 19, 2024
@hborla hborla added runtime The Swift Runtime objective-c interop Feature: Interoperability with Objective-C and removed triage needed This issue needs more specific labels labels Jul 14, 2024
@mikeash
Copy link
Contributor

mikeash commented Jul 15, 2024

Thanks for the report. The issue is that the compiler emits a mangled name with a private declaration on it, something like the encoding of __C.(MyName in _1AECFD08E409979057FF235F763A1E9D). The runtime doesn't expect this and the lookup fails. I'll get this to the right person. As a workaround, making the protocol internal avoids emitting the bad mangled name.

@AnthonyLatsis AnthonyLatsis added protocol Feature → type declarations: Protocol declarations @objc Feature → attributes: The @objc attribute metatypes Feature → types: Metatypes swift 6.0 and removed metatypes Feature → types: Metatypes labels Jul 15, 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 @objc Feature → attributes: The @objc attribute objective-c interop Feature: Interoperability with Objective-C protocol Feature → type declarations: Protocol declarations runtime The Swift Runtime swift 6.0
Projects
None yet
Development

No branches or pull requests

4 participants