Another improved error message request

D

DaZoner

I don't know if this case has been requested yet so sorry for the noise if
it has.

It would be nice if this code:

100.times | i |
puts i
end

.... reported that the "do" is missing on line 1 rather than saying syntax
error on line 2. The error can be difficult to find when you have nested
loops and much intervening code.
 
B

Brian Schröder

I don't know if this case has been requested yet so sorry for the noise if
it has.

It would be nice if this code:

100.times | i |
puts i
end

.... reported that the "do" is missing on line 1 rather than saying syntax
error on line 2. The error can be difficult to find when you have nested
loops and much intervening code.

This would indeed be nice, because I catch myself making this error also often. Somehow the do seems superfluent. But I don't think it would be possible to detect this always, because the | are parsed as bitwise or's, so there is only a superfluous end. The proposed indentation heuristic would give a correct result. So the missing end patch would help here.

(If I remember the thread correctly)

Regards,

Brian
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Another improved error message request"

|It would be nice if this code:
|
|100.times | i |
| puts i
|end

The point is that

100.times | i | puts

is totally valid syntax. It is very hard for a parser to detect this
type of error. If anyone comes up with an idea, please tell me.

matz.
 
S

Sam Roberts

Quoteing (e-mail address removed), on Tue, Nov 30, 2004 at 08:32:04AM +0900:
Hi,

In message "Re: Another improved error message request"

|It would be nice if this code:
|
|100.times | i |
| puts i
|end

The point is that

100.times | i | puts

is totally valid syntax. It is very hard for a parser to detect this
type of error. If anyone comes up with an idea, please tell me.

It is? Well, you would know... :) but I'm confused!

$ irb18
irb(main):001:0> 100.times | i | puts
LocalJumpError: no block given
from (irb):1:in `times'
from (irb):1

I'm building again, maybe my 1.8 is too far out of date.

Cheers,
Sam
 
H

Hal Fulton

Sam said:
It is? Well, you would know... :) but I'm confused!

$ irb18
irb(main):001:0> 100.times | i | puts
LocalJumpError: no block given
from (irb):1:in `times'
from (irb):1

I'm building again, maybe my 1.8 is too far out of date.

I think you're seeing a runtime error -- i.e., it is not one
detected by the parser.


Hal
 
J

Joel VanderWerf

Sam said:
Quoteing (e-mail address removed), on Tue, Nov 30, 2004 at 08:32:04AM +0900: ...


It is? Well, you would know... :) but I'm confused!

$ irb18
irb(main):001:0> 100.times | i | puts
LocalJumpError: no block given
from (irb):1:in `times'
from (irb):1

This is a LocalJumpError only because times happens to need a block.

irb(main):001:0> class Fixnum; def tmies; 4; end; end
=> nil
irb(main):002:0> i = 5
=> 5
irb(main):003:0> puts = 6
=> 6
irb(main):004:0> 100.tmies | i | puts
=> 7
 
F

Florian Gross

Sam said:
Quoteing (e-mail address removed), on Tue, Nov 30, 2004 at 08:32:04AM +0900:

It is? Well, you would know... :) but I'm confused!

$ irb18
irb(main):001:0> 100.times | i | puts
LocalJumpError: no block given
from (irb):1:in `times'
from (irb):1

Use ruby -c to check syntax:

C:\dev\ruby>ruby -c -e "100.times | i | puts"
Syntax OK
 
N

nobu.nokada

Hi,

At Tue, 30 Nov 2004 10:12:52 +0900,
Florian Gross wrote in [ruby-talk:121856]:
Use ruby -c to check syntax:

C:\dev\ruby>ruby -c -e "100.times | i | puts"
Syntax OK

And -w warns for it.

$ ruby -wc -e "100.times | i | puts"
-e:1: warning: useless use of | in void context
Syntax OK
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top