forked from vlang/v
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen: fix shortcircuiting of infix and/or expressions (vlang#21740)
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
vlib/v/tests/infix_expr_and_or_operate_unnecessary_eval_test.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
fn f(s string) !int { | ||
if s == '' { | ||
return error('invalid s') | ||
} | ||
return s.len | ||
} | ||
|
||
fn test_infix_expr_and_or_operate_unnecessary_eval() { | ||
v := '' | ||
x := v != 'xyz' || f(v)! < f('abc')! | ||
dump(x) | ||
assert x | ||
|
||
y := v == 'xyz' && f(v)! < f('abc')! | ||
dump(y) | ||
assert !y | ||
} |