Skip to content

Commit

Permalink
Fix some type-checking errors by using different method calls
Browse files Browse the repository at this point in the history
For example, use `.fetch` or `.dig` instead of `[]`, and use `===` instead of `is_a?` for checking types of objects.
  • Loading branch information
paracycle committed Mar 6, 2024
1 parent 1d87b8c commit 548b549
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/prism/parse_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def find_line(byte_offset)

while left <= right
mid = left + (right - left) / 2
return mid if offsets[mid] == byte_offset
return mid if (offset = offsets[mid]) == byte_offset

if offsets[mid] < byte_offset
if offset < byte_offset
left = mid + 1
else
right = mid - 1
Expand Down Expand Up @@ -262,7 +262,7 @@ def pretty_print(q)

# Returns true if the given other location is equal to this location.
def ==(other)
other.is_a?(Location) &&
Location === other &&
other.start_offset == start_offset &&
other.end_offset == end_offset
end
Expand Down Expand Up @@ -541,7 +541,7 @@ def pretty_print(q)

# Returns true if the given other token is equal to this token.
def ==(other)
other.is_a?(Token) &&
Token === other &&
other.type == type &&
other.value == value
end
Expand Down
2 changes: 2 additions & 0 deletions lib/prism/parse_result/newlines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def visit_statements_node(node)

# Walk the tree and mark nodes that are on a new line.
def mark_newlines!
value = self.value
raise "This method should only be called on a parse result that contains a node" unless Node === value
value.accept(Newlines.new(Array.new(1 + source.offsets.size, false))) # steep:ignore
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prism/translation/parser/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def to_a
index += 1
end
when :tFID
if !tokens.empty? && tokens[-1][0] == :kDEF
if !tokens.empty? && tokens.dig(-1, 0) == :kDEF
type = :tIDENTIFIER
end
end
Expand Down

0 comments on commit 548b549

Please sign in to comment.