#2747 closed Bug (No Bug)
Nested ternary operator returns incorrect results
| Reported by: | lcofresi | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.12.0 | Severity: | None |
| Keywords: | ternary nested | Cc: |
Description
This very simple code show the problem:
Local $v1 = 0, $v2 = 2
Local $v3 = ($v1 ? $v1 : ($v2 = 2 or $v2 = 3 ? 0 : 8))
MsgBox(0, "", $v3)
This should always display an integer value. Instead, it show the boolean value "True".
If one changes the value of $v2 in the first line (say, $v1 = 1), then it displays "8".
Attachments (0)
Change History (5)
follow-up: 2 comment:1 by , 12 years ago
| Resolution: | → No Bug |
|---|---|
| Status: | new → closed |
follow-up: 4 comment:2 by , 12 years ago
Replying to jchd18:
No bug here: you must use parenthesis to enclose the coumpound condition.
Then the ternary operator has the wrong precedence. That operator should always have the lowest precedence.
follow-up: 5 comment:4 by , 12 years ago
Replying to anonymous:
Replying to jchd18:
No bug here: you must use parenthesis to enclose the coumpound condition.
Then the ternary operator has the wrong precedence. That operator should always have the lowest precedence.
Can you see that parenthesis are being used ?
This is what the interpreter should do:
(1) First, solve the INNER parenthesis:
($v2 = 2 or $v2 = 3 ? 0 : 8)
That should return 0
(2) Second, solve the OUTER parenthesis, using the value obtained in (1)
($v1 ? $v1 : 0)
It then should return 0
comment:5 by , 12 years ago
Replying to lcofresi:
Replying to anonymous:
Replying to jchd18:
No bug here: you must use parenthesis to enclose the coumpound condition.
Then the ternary operator has the wrong precedence. That operator should always have the lowest precedence.
Can you see that parenthesis are being used ?
This is what the interpreter should do:
(1) First, solve the INNER parenthesis:
($v2 = 2 or $v2 = 3 ? 0 : 8)
That should return 0
(2) Second, solve the OUTER parenthesis, using the value obtained in (1)
($v1 ? $v1 : 0)
It then should return 0
RECTIFICATION AND MY APOLOGIES:
Sorry guys, I made a mistake. My apologies, specially to jchd18. You are right, and I was wrong.

No bug here: you must use parenthesis to enclose the coumpound condition.
Next time, please ask on the General Help forum to confirm bug status.