Skip to content

[Bug #19392] Make args connected with and/or as a body of method#8054

Open
yui-knk wants to merge 2 commits intoruby:masterfrom
yui-knk:endless_stmt
Open

[Bug #19392] Make args connected with and/or as a body of method#8054
yui-knk wants to merge 2 commits intoruby:masterfrom
yui-knk:endless_stmt

Conversation

@yui-knk
Copy link
Copy Markdown
Contributor

@yui-knk yui-knk commented Jul 10, 2023

def test = puts("foo") or puts("bar") is interrupted as def test = (puts("foo") or puts("bar")).

[Note] (2023-12-07) I created this patch to demonstrate it's not difficult to support this feature with LR parser generator. This doesn't mean I agree with the change.

`def test = puts("foo") or puts("bar")` is interrupted as
`def test = (puts("foo") or puts("bar"))`.
@zverok
Copy link
Copy Markdown
Contributor

zverok commented Nov 29, 2023

Unfortunately, this PR doesn't fix if/unless problem (which, despite my ticket's initial contents, is more critical than and/or):

def foo(arg) = p("OK") if arg

foo(false)
foo(true)

This is expected (with "natural" for the author precedences) to print "OK" once, but instead it fails with

test.rb:1:in `<main>': undefined local variable or method `arg' for main (NameError)

Apparently, it is still interpreted as

(def foo(arg) = p("OK")) if arg

Would it be possible to handle in the same manner? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants