Another improved error message request

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

···

On Tue, 30 Nov 2004 03:17:57 +0900 "DaZoner" <bugmenot@world.com> wrote:

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.

--
Brian Schröder
http://www.brian-schroeder.de/

Hi,

···

In message "Re: Another improved error message request" on Tue, 30 Nov 2004 03:17:57 +0900, "DaZoner" <bugmenot@world.com> writes:

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.

Quoteing matz@ruby-lang.org, on Tue, Nov 30, 2004 at 08:32:04AM +0900:

Hi,

>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... :slight_smile: 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

···

In message "Re: Another improved error message request" > on Tue, 30 Nov 2004 03:17:57 +0900, "DaZoner" <bugmenot@world.com> writes:

Sam Roberts wrote:

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... :slight_smile: 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

Sam Roberts wrote:

Quoteing matz@ruby-lang.org, on Tue, Nov 30, 2004 at 08:32:04AM +0900:

...

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... :slight_smile: 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

Sam Roberts wrote:

Quoteing matz@ruby-lang.org, on Tue, Nov 30, 2004 at 08:32:04AM +0900:

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... :slight_smile: 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

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

···

--
Nobu Nakada