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

Incorrect operator precedence in OutlineViewBinder.(_:,isExpandable:) #695

Open
deborahgoldsmith opened this issue Nov 13, 2020 · 0 comments

Comments

@deborahgoldsmith
Copy link
Contributor

In NSOutlineView+Changeset.swift:

    @objc(outlineView:isItemExpandable:)
    open func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
        guard let item = item as? ObjectTreeNode<Changeset.Collection.Children.Element> else { return false }
        return isItemExpandable?(item.value, outlineView) ?? item.children.isEmpty == false
    }

It look like the intent of the last line is:
return isItemExpandable?(item.value, outlineView) ?? (item.children.isEmpty == false)
However, ?? binds tighter than ==, so this line is actually:
return (isItemExpandable?(item.value, outlineView) ?? item.children.isEmpty) == false
which inverts the sense of isItemExpandable. Proposed fix:
return isItemExpandable?(item.value, outlineView) ?? !item.children.isEmpty
or altnernatively:
return isItemExpandable?(item.value, outlineView) ?? (item.children.isEmpty == false)
Workaround: user-supplied isItemExpandable must return false to make item expandable.
I can supply a PR if needed, but this is an easy fix.

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

1 participant