Project

General

Profile

Actions

Bug #19876

closed

Equality chaining

Added by kddnewton (Kevin Newton) 8 months ago. Updated 8 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:114707]

Description

It appears that you cannot chain ==, !=, <=>, =~, !~, ===:

foo == bar == baz

but you can chain all of the other operators:

1 << 2 << 3

I'm not sure if I've missed some. I would just like to know if this is a bug. If it's not, then I need to know which operators cannot be chained. At the moment all of these can be chained in YARP, but if it's desired behavior that that is a syntax error, I need to explicitly disallow this.

Updated by mame (Yusuke Endoh) 8 months ago

I think it is by design. They are marked as %nonassoc in parse.y.

https://github.com/ruby/ruby/blob/6e64d4370456190541705ec4c6cf3af6bf4ac647/parse.y#L1698

%nonassoc  tCMP tEQ tEQQ tNEQ tMATCH tNMATCH

Updated by kddnewton (Kevin Newton) 8 months ago

  • Status changed from Open to Closed

Okay. I will make this behavior match.

Actions

Also available in: Atom PDF

Like0
Like0Like0