@@ -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
0 commit comments