Skip to content

:has(...) returns true if argument is nil #250

@drewww

Description

@drewww

Passing either {nil} or simply nil will cause the for loop to be skipped and return true instead.

function Entity:has(...)

I discovered this because I had a typo in a component name and was surprised to find that :has was true for nil. I can see the case that passing in no arguments should be true, to match the behavior in :query(...). However I think in the case of has the intuitive behavior should be that it's true IFF all components are present.

Perhaps the answer should be a warning not a change to the return value.

The fixes for this seemed quickly to be somewhat complex to handle cases like {nil, realComponent} so I didn't try to work through them yet. Curious to discuss what "right" is here. Perhaps it is not actually a bug and should just be a documented behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions