Project

General

Profile

Actions

Bug #4198

closed

parse error involving spaceship operator

Added by spatulasnout (B Kelly) over 13 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2p110 (2010-12-20 revision 30269) [i386-darwin10.4.0]
Backport:
[ruby-core:33851]

Description

=begin
Hi,

I'm not sure if this is a bug? I'm getting a parse error on
the last line of the following code, unless I add parenthesis:

op-test-simple.rb

class Opper
  def / (other)
    self
  end
  def + (other)
    self
  end
  def <=> (other)
    self
  end
end

foo = Opper.new("foo")
bar = Opper.new("bar")
baz = Opper.new("baz")
quux = Opper.new("quux")
joe = Opper.new("joe")
mama = Opper.new("mama")
so = Opper.new("so")
fat = Opper.new("fat")
quick = Opper.new("quick")
brown = Opper.new("brown")
fox = Opper.new("fox")

foo + bar /
baz + quux /
joe + mama <=> so + fat /
quick + brown <=> fox

$ ruby19 -v op-test-simple.rb
ruby 1.9.2p110 (2010-12-20 revision 30269) [i386-darwin10.4.0]
op-test-simple.rb:29: syntax error, unexpected tCMP
quick + brown <=> fox
^
op-test-simple.rb:29: warning: useless use of a variable in void context

However, if parenthesis are added, like:

(quick + brown <=> fox)

or:

quick + (brown <=> fox)

then the parse error does not occur.

Regards,

Bill
=end

Actions #1

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Open to Rejected

Spaceship operator doesn't have asociativity, so a <=> b <=> c is parse error.

Actions

Also available in: Atom PDF

Like0
Like0