-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
[BUG] [Swift] Generating/Calling NSDecimalString function crashes the Swift compiler #19459
Comments
please share the change as a PR, I'd love to have this... thanks |
@aehlke Just generate your stuff that you normally do. Look for |
We are experiencing the same problem. The issue is critical 🔴 |
It has an easy workaround so I wouldn't call it critical at least - just drop in a template replacement |
Would also like to see a fix for this as we would like to rely on not having to update our generated code manually for CI. |
You don't need to manually change anything - override the specific template file in your automation |
I'm closing this issue, as this should now be fixed, if the issue is still present, please reopen this issue. |
Description
NSDecimalString generation causing a complier error after xCode beta 5 and 6.
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'
swiftlang/swift#75752
See the issue in swift language repo. If the new xCode 16 stays that way, openapi should change is generation. There is a workaround on the issue which works.
It is currently a problem regardless of the beta, since developers have to adapt the new xCode beta to prepare for iOS 18 which is coming out soon.
openapi-generator version
7.8
OpenAPI declaration file content or url
Generation Details
openapi-generator generate
-i etc/xxxyaml
-g swift5
-o Sources/Packages/XXX
--global-property models,supportingFiles,modelDocs=false
--model-name-suffix=DTO
--additional-properties=projectName= XXX,swiftPackagePath=Sources,removeMigrationProjectNameClass=true
Steps to reproduce
Related issues/PRs
Suggest a fix
Problematic generation:
extension KeyedEncodingContainerProtocol { public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws { var mutableValue = value let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US")) try encode(stringValue, forKey: key) } }
Workaround:
extension KeyedEncodingContainerProtocol { public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws { let decimalNumber = NSDecimalNumber(decimal: value) let numberFormatter = NumberFormatter() numberFormatter.numberStyle = .decimal numberFormatter.locale = Locale(identifier: "en_US") let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)" try encode(formattedString, forKey: key) } }
The text was updated successfully, but these errors were encountered: