Skip to content

Replace is_a? calls with convenient alternatives #15860

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

Merged

Conversation

straight-shoota
Copy link
Member

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

@@ -1099,7 +1099,7 @@ class Crystal::Repl::Compiler < Crystal::Visitor
end

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