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

[BUG] [Swift] Generating/Calling NSDecimalString function crashes the Swift compiler #19459

Closed
borsosbe opened this issue Aug 27, 2024 · 8 comments

Comments

@borsosbe
Copy link

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) } }

@aehlke
Copy link

aehlke commented Aug 29, 2024

please share the change as a PR, I'd love to have this... thanks

@borsosbe
Copy link
Author

@aehlke Just generate your stuff that you normally do. Look for NSDecimalString in the generated code and implement the workaround from the example.

@r3econ
Copy link

r3econ commented Sep 4, 2024

We are experiencing the same problem. The issue is critical 🔴

@aehlke
Copy link

aehlke commented Sep 4, 2024

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

@lilidotshi
Copy link
Contributor

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.

@aehlke
Copy link

aehlke commented Sep 7, 2024

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

@lilidotshi
Copy link
Contributor

@aehlke I opened up a PR with the changes that @borsosbe suggested here if you wanted to take a look. #19564

@4brunu
Copy link
Contributor

4brunu commented Oct 30, 2024

I'm closing this issue, as this should now be fixed, if the issue is still present, please reopen this issue.
Thanks

@4brunu 4brunu closed this as completed Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants