Modify

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#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 by jchd18, 12 years ago

Resolution: No Bug
Status: newclosed

No bug here: you must use parenthesis to enclose the coumpound condition.

Local $v1 = 0, $v2 = 2
Local $v3 = ($v1 ? $v1 : (($v2 = 2 or $v2 = 3) ? 0 : 8))
MsgBox(0, "", $v3)

Next time, please ask on the General Help forum to confirm bug status.

in reply to:  1 ; comment:2 by anonymous, 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.

comment:3 by jchd18, 12 years ago

Then file a feature request for this precise reason.
BTW I agree.

in reply to:  2 ; comment:4 by lcofresi, 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

in reply to:  4 comment:5 by lcofresi, 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.

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.