Skip to content

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

Description

@deborahgoldsmith

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions