Skip to content

Commit ee42e53

Browse files
committed
Fix error with prism when method given no arguments
such as: p = Proc.new This is now highlighted, and it wasn't before.
1 parent a75ddf7 commit ee42e53

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/error_highlight/base.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ def spot
244244
when :name
245245
prism_spot_call_for_name
246246
when :args
247-
prism_spot_call_for_args
247+
if @node.arguments.nil?
248+
prism_spot_call_for_name
249+
else
250+
prism_spot_call_for_args
251+
end
248252
end
249253

250254
when :local_variable_operator_write_node

test/test_error_highlight.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def assert_error_message(klass, expected_msg, &blk)
6363
ONE_RECV_MESSAGE = "1:Integer"
6464
end
6565

66+
def using_prism?
67+
RubyVM::InstructionSequence.compile("").to_a[4][:parser] == :prism
68+
end
69+
6670
def test_CALL_noarg_1
6771
assert_error_message(NoMethodError, <<~END) do
6872
undefined method `foo' for #{ NIL_RECV_MESSAGE }
@@ -197,6 +201,18 @@ def test_CALL_arg_6
197201
end
198202
end
199203

204+
def test_call_node_no_arguments
205+
assert_error_message(ArgumentError, <<~END) do
206+
tried to create Proc object without a block (ArgumentError)
207+
208+
Proc.new
209+
^^^^
210+
END
211+
212+
Proc.new
213+
end
214+
end
215+
200216
def test_QCALL_1
201217
assert_error_message(NoMethodError, <<~END) do
202218
undefined method `foo' for #{ ONE_RECV_MESSAGE }
@@ -1339,7 +1355,7 @@ def test_spot_with_node
13391355
# We can't revisit instruction sequences to find node ids if the prism
13401356
# compiler was used instead of the parse.y compiler. In that case, we'll
13411357
# omit some tests.
1342-
omit if RubyVM::InstructionSequence.compile("").to_a[4][:parser] == :prism
1358+
omit if using_prism?
13431359

13441360
begin
13451361
raise_name_error

0 commit comments

Comments
 (0)