From: "tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "tenderlovemaking (Aaron Patterson)" <noreply@ruby-lang.org>
Subject: [ruby-core:120103] [Ruby master Bug#20918] Prism error indicates line number of `-e` that does not exist
Date: Wed, 04 Dec 2024 16:15:58 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-110851.20241204161558.18@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20918.20241128043850.18@ruby-lang.org>
Issue #20918 has been updated by tenderlovemaking (Aaron Patterson).
kddnewton (Kevin Newton) wrote in #note-3:
> I looked into this this morning, it looks like ruby.c is automatically concatenating a \n onto the -e script here: https://github.com/ruby/ruby/blob/f43585b02c3634ab9a4e54049b08e04ab1a640fd/ruby.c#L1303. Is this desired behavior?
I'm not sure if it matters. If you have a script with one line (that has a newline), Prism will report line 2 as the error.
```
[aaron@tc-lan-adapter ~/g/ruby (master)]$ cat x.rb
foo(
[aaron@tc-lan-adapter ~/g/ruby (master)]$ od -c x.rb
0000000 f o o ( \n
0000005
[aaron@tc-lan-adapter ~/g/ruby (master)]$ wc -l x.rb
1 x.rb
[aaron@tc-lan-adapter ~/g/ruby (master)]$ ./miniruby x.rb
x.rb: x.rb:2: syntax error found (SyntaxError)
1 | foo(
> 2 |
| ^ unexpected end-of-input; expected a `)` to close the arguments
[aaron@tc-lan-adapter ~/g/ruby (master)]$
```
It's fine for newlines to appear in method parameters as well as blocks, so Prism considers the EOF token to be the "error token". Indeed EOF "occurs" on line 2 (since it's after the newline), but since nobody writes EOF in to their files, I think we should consider the error to have occurred at the newline preceding EOF.
One more example:
```
[aaron@tc-lan-adapter ~/g/ruby (master)]$ cat x.rb
foo(
[aaron@tc-lan-adapter ~/g/ruby (master)]$ wc -l x.rb
5 x.rb
[aaron@tc-lan-adapter ~/g/ruby (master)]$ od -c x.rb
0000000 f o o ( \n \n \n \n \n
0000011
[aaron@tc-lan-adapter ~/g/ruby (master)]$ ./miniruby x.rb
x.rb: x.rb:6: syntax error found (SyntaxError)
4 |
5 |
> 6 |
| ^ unexpected end-of-input; expected a `)` to close the arguments
[aaron@tc-lan-adapter ~/g/ruby (master)]$
```
Most tools agree the above file only has 5 lines in it, but Prism reports the error on line 6. IMO errors should only occur on lines that exist.
----------------------------------------
Bug #20918: Prism error indicates line number of `-e` that does not exist
https://bugs.ruby-lang.org/issues/20918#change-110851
* Author: mame (Yusuke Endoh)
* Status: Assigned
* Assignee: prism
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
```
$ ruby -e 'foo('
-e: -e:2: syntax error found (SyntaxError)
1 | foo(
> 2 |
| ^ unexpected end-of-input; expected a `)` to close the arguments
```
It says `-e:2`, but there is no line 2 in `-e 'foo('`.
`eval("foo(")` reports line 1, so I guess this issue is only for `-e`.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
next prev parent reply other threads:[~2024-12-04 16:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 4:38 [ruby-core:120035] " mame (Yusuke Endoh) via ruby-core
2024-11-30 23:04 ` [ruby-core:120072] " ydah (Yudai Takada) via ruby-core
2024-12-04 14:58 ` [ruby-core:120101] " kddnewton (Kevin Newton) via ruby-core
2024-12-04 16:15 ` tenderlovemaking (Aaron Patterson) via ruby-core [this message]
2024-12-12 10:56 ` [ruby-core:120210] " mame (Yusuke Endoh) via ruby-core
2024-12-12 18:44 ` [ruby-core:120222] " tenderlovemaking (Aaron Patterson) via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-110851.20241204161558.18@ruby-lang.org \
--to=ruby-core@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).