Skip to content

Syntax error with &.< in combination with other operators #3763

@Papierkorb

Description

@Papierkorb

Hello,

while testing my Ruby 2.3 application with JRuby master I noticed it throwing a syntax error when using &. on an operator.

Example code

# Test case giving unexpected behaviour:
{ foo: 1 }.reject{|_, value| false || value&.<(0)}
#=> SyntaxError: unexpected tLPAREN

# Removing the `false ||`
{ foo: 1 }.reject{|_, value| value&.<(0)}
#=> { foo: 1 } # This one works!

# Adding parantheses
{ foo: 1 }.reject{|_, value| false || (value&.<(0))}
#=> { foo: 1 } # This one works too!

On MRI 2.3.0p0 all reject lines give the same, expected result. On JRuby, the first line fails with a SyntaxError.

Environment

Expected Behavior

All lines return { foo: 1 }

Actual Behavior

The first gives a SyntaxError

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions