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

Fixes #1041 and #1038 on linux variants #1048

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

monomadic
Copy link

@monomadic monomadic commented Feb 7, 2020

Compilation fails due to tighter type restrictions on newer swift builds. Casting works and produces no errors. See #1041 and #1038 for complaints on this issue.

  • Does this have tests?
    Unnecessary, existing tests cover this case (it is purely a type definition in two places)
  • Does this have documentation?
    Not needed
  • Does this break the public API (Requires major version bump)?
    No
  • Is this a new feature (Requires minor version bump)?
    No

Compilation fails due to tighter type restrictions on newer swift builds. Casting works and produces no errors.
@@ -1212,7 +1212,7 @@ public func > (lhs: JSON, rhs: JSON) -> Bool {
public func < (lhs: JSON, rhs: JSON) -> Bool {

switch (lhs.type, rhs.type) {
case (.number, .number): return lhs.rawNumber < rhs.rawNumber
case (.number, .number): return lhs.rawNumber as NSNumber > rhs.rawNumber as NSNumber

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deathdisco Shouldn't this be < (instead of >)?
(Should explain for the failing tests 😉 )

fixed lhs greater-than comparison to reflect correct comparison operator
@eritbh
Copy link

eritbh commented Apr 4, 2020

Any movement here? I'm developing a cross-platform library that depends on SwiftyJSON and having this fixed would be a huge benefit!

@diskshima
Copy link

diskshima commented Apr 4, 2020

@monomadic This isn't compiling (at least on a mac).

I think the Swift compiler thinks < is part of a Generic statement and is erroring with

❌  /Users/travis/build/SwiftyJSON/SwiftyJSON/Source/SwiftyJSON/SwiftyJSON.swift:1215:79: expected '>' to complete generic argument list

    case (.number, .number): return lhs.rawNumber as NSNumber < rhs.rawNumber as NSNumber
                                                              ^

on Travis CI here.

You need to put brackets around the left side of <.

    case (.number, .number): return (lhs.rawNumber as NSNumber) < rhs.rawNumber as NSNumber
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Need brackets

@eritbh
Copy link

eritbh commented Apr 4, 2020

After applying that fix on a local checkout of this branch under Ubuntu 18.04 in WSL 2, it still doesn't work. I've changed the line to:

    case (.number, .number): return (lhs.rawNumber as NSNumber) < (rhs.rawNumber as NSNumber)

When adding the local copy as a dependency of another project and running swift test on that project, I get the following error:

% swift test
/home/george/Code/monomadic/SwiftyJSON/Source/SwiftyJSON/SwiftyJSON.swift:1215:65: error: ambiguous use of operator '<'
    case (.number, .number): return (lhs.rawNumber as NSNumber) < (rhs.rawNumber as NSNumber)
                                                                ^
/home/george/Code/monomadic/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

It seems there's a deeper issue that this PR doesn't address at all. Is it possible that this is a bug in the Linux implementation of Foundation?

@diskshima
Copy link

diskshima commented Apr 5, 2020

@Geo1088 Yeah, you're right. Sorry jumped the gun a bit.

The quick fix might be to rename the operators like this.
The build passes on macOS and Linux but the tests still gives errors around INT64_MAX and autoreleasepool on Linux (tested on a Docker instance based on Ubuntu 18) and obviously may not be the right way to fix it.

@seriyvolk83
Copy link

Consider #1083 instead.

@LinusGeffarth
Copy link

Any update on this? Seeing this error still

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

Successfully merging this pull request may close these issues.

None yet

5 participants