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

crash when build on linux #1091

Open
bordunosp opened this issue Feb 22, 2021 · 6 comments
Open

crash when build on linux #1091

bordunosp opened this issue Feb 22, 2021 · 6 comments

Comments

@bordunosp
Copy link

bordunosp commented Feb 22, 2021

swift:5.3.3
SwiftyJSON:5.0.0

/var/www/app/.build/checkouts/SwiftyJSON/Source/SwiftyJSON/SwiftyJSON.swift:1215:51: error: ambiguous use of operator '<'
    case (.number, .number): return lhs.rawNumber < rhs.rawNumber
                                                  ^
/var/www/app/.build/checkouts/SwiftyJSON/Source/SwiftyJSON/SwiftyJSON.swift:1251:6: note: found this candidate
func < (lhs: NSNumber, rhs: NSNumber) -> Bool {
     ^
Foundation.NSNumber:2:24: note: found this candidate
    public static func < (lhs: NSNumber, rhs: NSNumber) -> Bool
@iliasaz
Copy link

iliasaz commented Jul 16, 2021

I'm having the same issue in swift 5.4. Is there a workaround?

@TheRealMaN
Copy link

Same here, still no fix?

@bhirt
Copy link

bhirt commented Aug 22, 2023

I am also getting this error with the current version. Using swift 5.8. I'm not sure why SwiftyJSON is implementing comparators for NSNumber.

Just out of curiosity, I wrote a trivial program to compare two NSNumber. I ran one on my mac and another on a linux box. The linux box runs just fine, but the mac version won't compile because there is no comparator for NSNumber. It seems like Foundation on linux implements it, while Foundation on mac does not. Maybe I am misreading it. Here is the program:

import Foundation

let n1 = NSNumber(value: 1)
let n2 = NSNumber(value: 2)

if (n1 < n2) {
    print("1 < 2")
}
else {
    print("2 < 1")
}

Running on linux:

root@localhost:/# uname -a
Linux localhost 4.15.0-159-generic #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
root@localhost:/# swift --version
Swift version 5.8.1 (swift-5.8.1-RELEASE)
Target: x86_64-unknown-linux-gnu
root@localhost:/# swift test.swift 
1 < 2
root@localhost:/#

Trying no run on mac studio:

pansy:tmp bhirt$ uname -a
Darwin pansy.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64
pansy:tmp bhirt$ swift --version
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
pansy:tmp bhirt$ swift test.swift 
test.swift:6:5: error: 'NSNumber' is not convertible to 'Decimal'
if (n1 < n2) {
    ^
test.swift:6:5: note: did you mean to use 'as!' to force downcast?
if (n1 < n2) {
    ^
       as! Decimal
test.swift:6:10: error: 'NSNumber' is not convertible to 'Decimal'
if (n1 < n2) {
         ^
test.swift:6:10: note: did you mean to use 'as!' to force downcast?
if (n1 < n2) {
         ^
            as! Decimal
pansy:tmp bhirt$

Possibly we can just conditional compile based on #if os(Linux). Windows might have the same issue, but I'm unable to test that.

@bhirt
Copy link

bhirt commented Aug 22, 2023

Just another follow up:

import Foundation

let n1 = NSNumber(value: 1)

if let _ = n1 as? any Comparable {
    print("n1 is Comparable")
}
else {
    print("n1 is NOT Comparable")
}

Linux:

root@localhost:/# swift test.swift 
test.swift:5:15: warning: conditional cast from 'NSNumber' to 'any Comparable' always succeeds
if let _ = n1 as? any Comparable {
              ^
n1 is Comparable

Mac

pansy:tmp bhirt$ swift test.swift 
n1 is NOT Comparable

@robert-dodier
Copy link

For the record, I've bumped into this same issue too. Ubuntu 22.04, swift 5.9.1 (x86_64).

@pianocomposer321
Copy link

I also have this issue, has anyone found a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants