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

Sort Properties After Creation #175

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

LePips
Copy link
Contributor

@LePips LePips commented Dec 19, 2022

Sorts created properties, which go through their own independent renamings if applicable, instead of the raw keys.

@LePips
Copy link
Contributor Author

LePips commented Dec 19, 2022

Interesting, the tests' type checker couldn't do that inference, I think due to handle(error:_).

Edit:
After a minimal playground test, seems like so. I see now that the interference was removed from the function return type, but strange that it works on my machine (cleaned and everything). However, the test below doesn't work on my machine. 🤷

Edit edit:
Seems like a Swift 5.6 issue.

Minimal Example
let handleWarningAsError = false

func handle<T>(warning: String) -> T? {
    if handleWarningAsError {
        fatalError()
    } else {
        print(warning)
        return nil
    }
}

let keys = ["foo", "bar"]

struct Property {
    
    let name: String
    let uuid = UUID()
}

let properties = keys.compactMap { key in // Error: ambiguous, fix with [Property]
    
    if key == "foo" {
        return handle(warning: "You are foo, I don't like you")
    }
    
    return Property(name: key)
}

print(properties)

@LePips
Copy link
Contributor Author

LePips commented Jan 10, 2023

@liamnichols I apologize for the ping, could this and #177 receive a review as I would like to go ahead with some work that would use these features. Thank you!

Copy link
Member

@liamnichols liamnichols left a comment

Choose a reason for hiding this comment

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

Hi @LePips, really sorry about the delay in getting though these notifications! Thanks for taking the time to work on this, I really appreciate it!

The changes looks good to me assuming that it is doing what you say it does, but could you maybe replicate it in the tests somehow so that we can be sure not to break the behaviour in the future by mistake? 🙏

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.

useSwiftyPropertyNames and sortPropertiesAlphabetically ordering
2 participants