Skip to content

Replace is_a? calls with convenient alternatives#15860

Merged
straight-shoota merged 3 commits intocrystal-lang:masterfrom
straight-shoota:chore/style-is_a
Jun 5, 2025
Merged

Replace is_a? calls with convenient alternatives#15860
straight-shoota merged 3 commits intocrystal-lang:masterfrom
straight-shoota:chore/style-is_a

Conversation

@straight-shoota
Copy link
Member

These were discovered with ameba's Style/IsAFilter and Style/IsANil rules.


private def dispatch_class_var(owner : Type, metaclass : Bool, node : ASTNode, &)
types = owner.all_subclasses.select { |t| t.is_a?(ClassVarContainer) }
types = owner.all_subclasses.select(ClassVarContainer)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is failing because types must be Array(Crystal::Type) because we also add owner to it.
But select(ClassVarContainer) would return Array(Crystal::ClassVarContainer).

It's probably best to refactor this a bit to make the typing more explicit.

@straight-shoota straight-shoota added this to the 1.17.0 milestone Jun 4, 2025
@straight-shoota straight-shoota mentioned this pull request Jun 4, 2025
@straight-shoota straight-shoota merged commit b987c1f into crystal-lang:master Jun 5, 2025
36 checks passed
@straight-shoota straight-shoota deleted the chore/style-is_a branch June 5, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants