Skip to content

Commit 24bdf87

Browse files
committed
Make rake typecheck:steep pass
1 parent 175958a commit 24bdf87

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/prism/parse_result.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def code_units_column(byte_offset, encoding)
147147
def line_and_column_to_byte_offset(line, column)
148148
line_start = offsets[line - 1]
149149
line_end = offsets[line]
150-
line_start + @source.byteslice(line_start, line_end)[0...column].bytesize
150+
byte_column = (@source.byteslice(line_start, line_end) or raise)[0...column]&.bytesize #: Integer
151+
line_start + byte_column
151152
end
152153

153154
# Freeze this object and the objects it contains.
@@ -921,7 +922,7 @@ def self.node_for(callable)
921922
source_location = callable.source_location
922923
raise ArgumentError, "#source_location is nil for #{callable}" if source_location.nil?
923924
raise ArgumentError, '#source_location does not contain column and end_line, this method only works on Ruby 4+' if source_location.size != 5
924-
file, start_line, start_column, end_line, end_column = source_location
925+
file, start_line, start_column, end_line, end_column = source_location #: [String, Integer, Integer, Integer, Integer]
925926

926927
unless File.exist?(file)
927928
raise ArgumentError, "#source_location[0] is #{file} but this file does not exist"
@@ -945,8 +946,10 @@ def self.node_for(callable)
945946
when CallNode
946947
# Proc#source_location returns start_column 5 for `proc { ... }` (the `{`)
947948
node.block.is_a?(BlockNode) && node.block.opening_loc.start_offset == start_offset && node.end_offset == end_offset
949+
else
950+
false
948951
end
949-
end
952+
end #: DefNode | LambdaNode | CallNode
950953

951954
raise ArgumentError, "Could not find node for #{callable} in #{file} at (#{start_line},#{start_column})-(#{end_line},#{end_column})" unless found
952955
found

templates/sig/prism.rbs.erb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ module Prism
3131
?main_script: bool,
3232
?offset: Integer,
3333
?scopes: Array[Array[Symbol]],
34-
?verbose: bool
34+
?verbose: bool,
35+
?version: String
3536
) -> <%= return_type %>
3637
<%- end -%>
3738

@@ -68,7 +69,8 @@ module Prism
6869
?main_script: bool,
6970
?offset: Integer,
7071
?scopes: Array[Array[Symbol]],
71-
?verbose: bool
72+
?verbose: bool,
73+
?version: String
7274
) -> <%= return_type %>
7375
<%- end -%>
7476

@@ -86,7 +88,8 @@ module Prism
8688
?main_script: bool,
8789
?offset: Integer,
8890
?scopes: Array[Array[Symbol]],
89-
?verbose: bool
91+
?verbose: bool,
92+
?version: String
9093
) -> ParseResult
9194

9295
def self.scope: (?locals: Array[Symbol], ?forwarding: Array[Symbol]) -> Scope

0 commit comments

Comments
 (0)