#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)
comment:1 follow-up: ↓ 2 Changed 11 years ago by jchd18
- Resolution set to No Bug
- Status changed from new to closed
comment:2 in reply to: ↑ 1 ; follow-up: ↓ 4 Changed 11 years ago by 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.
comment:3 Changed 11 years ago by jchd18
Then file a feature request for this precise reason.
BTW I agree.
comment:4 in reply to: ↑ 2 ; follow-up: ↓ 5 Changed 11 years ago by 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
comment:5 in reply to: ↑ 4 Changed 11 years ago by lcofresi
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.
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
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.