[BUG] Unexpected syntax error

D

Daniel Harple

$ ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]

# Example to illustrate the problem
def foo1
p (1..10).method:)each)
end

def foo2()
p((1..10).method:)each))
end

def foo3()
p (1..10).method:)each)
end

foo1 # -> No error
foo2 # -> No error
foo3 # -> Error

__END__

-- Daniel
 
P

Park Heesob

Hi,

From: Daniel Harple <[email protected]>
Reply-To: (e-mail address removed)
To: (e-mail address removed) (ruby-talk ML)
Subject: [BUG] Unexpected syntax error
Date: Mon, 20 Feb 2006 09:10:54 +0900

$ ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]

# Example to illustrate the problem
def foo1
p (1..10).method:)each)
end

def foo2()
p((1..10).method:)each))
end

def foo3()
p (1..10).method:)each)
end

foo1 # -> No error
foo2 # -> No error
foo3 # -> Error

__END__

-- Daniel
It reminds me an old thread
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/12896


def foo1
p (2.4/0.2).to_i
end
def foo2()
p ((2.4/0.2).to_i)
end
def foo3()
p (2.4/0.2).to_i
end

foo1 # -> 11
foo2 # -> 11
foo3 # -> 12.0

__END__

Regards,

Park Heesob
 
E

Eric Hodel

$ ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]

# Example to illustrate the problem
def foo1
p (1..10).method:)each)
end

def foo2()
p((1..10).method:)each))
end

def foo3()
p (1..10).method:)each)
end

foo1 # -> No error
foo2 # -> No error
foo3 # -> Error

Ruby thinks those are argument parentheses. This may not be a bug.

-:11: warning: don't put space before argument parentheses
#<Method: Range#each>
#<Method: Range#each>
1..10
-:11:in `method': undefined method `each' for class
`NilClass' (NameError)
from -:11:in `foo3'
from -:16
$ parse_tree_show -f
p (1..10).method:)each)
(eval):1: warning: (...) interpreted as grouped expression
[[:class,
:Example,
:Object,
[:defn,
:example,
[:scope,
[:block,
[:args],
[:fcall,
:p,
[:array, [:call, [:lit, 1..10], :method, [:array,
[:lit, :each]]]]]]]]]]
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Unexpected syntax error"

|Ruby thinks those are argument parentheses. This may not be a bug.

This is a bug, and I fixed it last night(JST).

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top