Skip to content

Conversation

@amomchilov
Copy link
Contributor

No description provided.

@amomchilov amomchilov changed the title Misc. tidying Remove redundant nil checks in RBI::Visitor Jun 11, 2024

sig { override.params(node: T.nilable(Node)).void }
def visit(node)
return unless node
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this causes a type failure before, even if I make Indexable a subtype of Node (by adding requires_ancestor { Node }):

lib/rbi/rewriters/merge_trees.rb:155: Expected RBI::Node but found T.all(RBI::Indexable, T.nilable(RBI::Node)) for argument right https://srb.help/7002
     155 |                make_conflict_tree(prev, node)
                                                   ^^^^

Should T.all(RBI::Indexable, T.nilable(RBI::Node)) be simplified to T.all(RBI::Indexable, RBI::Node) (since it needs to be Indexable, it can't also be nil), and therefore be a subtype of RBI::Node?


sig { override.params(node: T.nilable(Node)).void }
def visit(node)
return unless node
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not convinced removing these is a great idea. They're technically redundant, but they also fail fast on nil, which would be a really common case to hit (rather than doing 3 Class#=== checks below)

# applies the ordering rules from the node_rank method as much as possible, while preserving visibility.
sorted_nodes = node.nodes.chunk do |n|
n.is_a?(Visibility)
end.flat_map do |_, nodes|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no Rubocop rule that can enforce this (last I checked), but having end.something_else do || on the same line is kinda weird, and reads better when it's one operation per line IMO.

Comment on lines -13 to -14
case node
when Tree
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing these case statements with only one when worked out nicely.

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

Successfully merging this pull request may close these issues.

1 participant