diff options
| author | Ufuk Kayserilioglu <ufuk.kayserilioglu@shopify.com> | 2024-03-06 14:34:04 -0500 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-03-06 21:37:52 +0000 |
| commit | 8dfe0c7c28fcaff1d52ab7f2751188f2e89b2347 (patch) | |
| tree | 5f28a98a0e9351d1ce7a3200859118d869375d31 /lib | |
| parent | ddc81ee3f996308482bc566c3048c5965f608ad0 (diff) | |
[ruby/prism] Fix some type-checking errors by using different method calls
For example, use `.fetch` or `.dig` instead of `[]`, and use `===` instead of `is_a?` for checking types of objects.
https://github.com/ruby/prism/commit/548b54915f
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/prism/parse_result.rb | 8 | ||||
| -rw-r--r-- | lib/prism/parse_result/newlines.rb | 2 | ||||
| -rw-r--r-- | lib/prism/translation/parser/lexer.rb | 2 |
3 files changed, 7 insertions, 5 deletions
diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index 102567f59c..bd2349f60b 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -87,9 +87,9 @@ module Prism 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 @@ -262,7 +262,7 @@ module Prism # 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 @@ -541,7 +541,7 @@ module Prism # 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 diff --git a/lib/prism/parse_result/newlines.rb b/lib/prism/parse_result/newlines.rb index 927c17fe2f..03acb0b862 100644 --- a/lib/prism/parse_result/newlines.rb +++ b/lib/prism/parse_result/newlines.rb @@ -58,6 +58,8 @@ module Prism # 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 diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index b710b1981b..bc7e77f291 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -302,7 +302,7 @@ module Prism index += 1 end when :tFID - if !tokens.empty? && tokens[-1][0] == :kDEF + if !tokens.empty? && tokens.dig(-1, 0) == :kDEF type = :tIDENTIFIER end end |
