Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone && and || trigger infinite loop #371

Open
Lydxn opened this issue Oct 9, 2023 · 3 comments
Open

Standalone && and || trigger infinite loop #371

Lydxn opened this issue Oct 9, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Lydxn
Copy link

Lydxn commented Oct 9, 2023

Either of these two lines will trigger an infinite loop, where you would expect them to do nothing:

0 && 1
1 || 0

This behavior seems to magically resolve when the expression is assigned to a variable, e.g.

_ = 0 && 1
@skiars skiars added the bug Something isn't working label Oct 10, 2023
@s-hadinger
Copy link
Contributor

I cannot reproduce:

> 0 && 1
false
> 1 || 0
true
> def f() 0 && 1 end
syntax_error: stdin:1: strict: expression without side effect detected
> def f() return 0 && 1 end
> f()
false

@skiars
Copy link
Member

skiars commented Oct 10, 2023

These lines need to be parsed together. Try 0 && 1 1 || 0 in REPL.

@s-hadinger
Copy link
Contributor

Ah yes indeed. What's interesting is when running in strict mode, it gets the following error (which is expected):

> 0 && 1 1 || 0
syntax_error: stdin:1: strict: expression without side effect detected

Now looking at the produced code:

> def f() 0 && 1 1 || 0 end
> import debug
> debug.codedump(f)
source 'stdin', function 'f':
; line 1
  0000  LDCONST	R0	K0
  0001  JMPF	R0	#0001
  0002  LDCONST	R0	K1
  0003  JMPT	R0	#0003
  0004  RET	0

There is definitely a problem at line 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants