-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Calling NSDecimalString function crashes the Swift compiler (also FB14697842) #75752
Comments
Do you have a workaround? |
The only workaround I know is going back to Xcode 16 beta 4 (and praying that this issue gets fixed soon). |
Experiencing the same issue. |
ok. There seems to be a work-around. It's quite verbose, but it works:
|
EDIT: Please see @robertmryan's comment below before choosing to use the approach I suggested here. It seems this is a known issue on Xcode 16. According to the release notes, the suggested workaround is to use Decimal.FormatStyle. If you're supporting iOS 15.0 and above, you can do something like this too: let decimalNumber: Decimal = 12345.67
let formatStyle = Decimal.FormatStyle(locale: locale)
let formattedNumber = decimalNumber.formatted(formatStyle)
let formattedNumberStr = String(formattedNumber) The main advantage of this approach is that you don't have to deal with optionals. |
I agree that for now we can just avoid using |
I would be cautious with this: If the locale is your |
@robertmryan that solution has merged so you might want to copy your feedback to that PR or share an alternative |
Are you talking about [swift5] Fix Xcode 16 compilation crash with Extensions.swift generation #19564? All those changes were using Or is there some other PR that you are referencing? |
Got the same issue on 16.0 RC Can I go back to a 16.0 beta where this is not an issue? |
Thanks for pointing that out, @robertmryan! I wasn’t aware of that important difference in behavior. Do you know if there’s a way for |
@alvesmarcel – No, I don’t. So, when trying to format for the end-user’s preferred format, I stick with To make using extension String.StringInterpolation {
mutating func appendInterpolation<T: Numeric>(_ value: T, using formatter: NumberFormatter) {
if let formattedValue = formatter.string(for: value) {
appendLiteral(formattedValue)
}
}
} Then I can use let string = "\(value, using: formatter)") FWIW, with floating points, you can use the let string = "\(value, specifier: "%.2f")" But that does not work with |
Description
The following code that calls NSDecimalString crashes the compiler with the message:
SILFunction type mismatch for 'NSDecimalString': '$@convention(c) (UnsafePointer, Optional) -> @autoreleased Optional' != '$@convention(c) (UnsafePointer, Optional) -> @autoreleased NSString'
Reproduction
Stack dump
Expected behavior
I expect it compile without a crash.
Environment
swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1)
Target: arm64-apple-macosx14.0
Additional information
DecimalStringBug.zip
The text was updated successfully, but these errors were encountered: