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

Different behavior with interpreted vs built program #79568

Open
keith opened this issue Feb 23, 2025 · 2 comments
Open

Different behavior with interpreted vs built program #79568

keith opened this issue Feb 23, 2025 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@keith
Copy link
Member

keith commented Feb 23, 2025

Reproduction

With this code:

import AppKit
import Foundation

print(NSAttributedString(rtf: Data(), documentAttributes: nil) as Any)

If you run directly with swift:

swift repro.swift

it prints nil.

If you instead compile and run with:

swiftc repro.swift -o repro && ./repro

It crashes with:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteAttributedString initWithRTF:documentAttributes:]: unrecognized selector sent to instance 0x600002e9f6c0'
*** First throw call stack:
(
        0   CoreFoundation                      0x0000000183996e80 __exceptionPreprocess + 176
        1   libobjc.A.dylib                     0x000000018347ecd8 objc_exception_throw + 88
        2   CoreFoundation                      0x0000000183a4c1d8 -[NSObject(NSObject) __retain_OA] + 0
        3   CoreFoundation                      0x0000000183903820 ___forwarding___ + 1568
        4   CoreFoundation                      0x0000000183903140 _CF_forwarding_prep_0 + 96
        5   repro                               0x0000000104f27dc0 $sSo18NSAttributedStringC6AppKitE3rtf18documentAttributesABSg10Foundation4DataV_SAySo12NSDictionaryCSgGSgtcfcTO + 60
        6   repro                               0x0000000104f27c70 $sSo18NSAttributedStringC6AppKitE3rtf18documentAttributesABSg10Foundation4DataV_SAySo12NSDictionaryCSgGSgtcfC + 60
        7   repro                               0x0000000104f27b44 main + 80
        8   dyld                                0x00000001834bc274 start + 2840
)
libc++abi: terminating due to uncaught exception of type NSException
zsh: abort      ./repro

Expected behavior

Ideally it would exhibit the same behavior in both cases, with whatever behavior is "correct". I imagine in this specific case the cause is a bug in Foundation not Swift causing the runtime crash.

Environment

% swiftc -version
xswift-driver version: 1.115.1 cApple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
% xcodebuild -version
Xcode 16.2
Build version 16C5032a
% sw_vers
ProductName:            macOS
ProductVersion:         15.2
BuildVersion:           24C101

Additional information

No response

@keith keith added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 23, 2025
@keith
Copy link
Member Author

keith commented Feb 23, 2025

Fun workaround for this specific crash:

import AppKit
import Foundation

_ = NSDocument()
print(NSAttributedString(rtf: Data(), documentAttributes: nil) as Any)

Works in both modes. I'm hoping this issue can be used to track the underlying issue here as well but lmk if I should file a radar instead

@keith
Copy link
Member Author

keith commented Feb 23, 2025

using that actually requires some async juggling so _ = String(describing: NSDocument.self) works as well (just _ = NSDocument.self) does not

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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant