Project

General

Profile

Actions

Bug #18396

open

An unexpected "hash value omission" syntax error when without parentheses call expr follows

Added by koic (Koichi ITO) over 2 years ago. Updated almost 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-12-07T23:18:11Z master 4a3e7984bf) [x86_64-darwin19]
[ruby-core:106543]

Description

Summary

I encountered an unexpected "hash value omission" syntax error when parentheses call expression follows:

% cat example.rb
foo key:
foo arg
% ruby -cv /tmp/b.rb
ruby 3.1.0dev (2021-12-07T23:18:11Z master 4a3e7984bf) [x86_64-darwin19]
example.rb:2: syntax error, unexpected local variable or method, expecting `do' or '{' or '('
foo arg

Additional Information

The following is a traditional usage.

# No errors.
foo key: key
foo arg

A syntax error is unexpectedly raised when hash value omission argument without parentheses is followed by a method call without parentheses.

# No errors is expected, but syntax error is raised.
foo key:
foo arg

No error occurs if any of the calls have parentheses.

# No errors.
foo(key:)
foo arg
# Also no errors.
foo key:
foo(arg)

No error occurs when calling alone.

# No errors.
foo key:

I encountered this error while trying to apply hash value omission to RSpec code of a real-world application (proprietary) .
But this is a new Ruby 3.1 syntax and may not be supported yet. Thank you.

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0