Modify

Opened 11 years ago

Closed 9 years ago

#2589 closed Bug (Works For Me)

Exit has to be put in function in order to use it in short if.

Reported by: shadow_iso@… Owned by:
Milestone: Component: AutoIt
Version: 3.3.10.2 Severity: None
Keywords: short if, exit, bug Cc:

Description

The new short if does not accept Statements like Exit.
You have to put it in a function first.

Example:
1<2?MsgBox(0,0,0):Exit ;does not work

1<2MsgBox(0,0,0):ex()
Func ex()
Exit
EndFunc ;does work

Attachments (0)

Change History (8)

comment:1 Changed 11 years ago by anonymous

lol

comment:2 Changed 11 years ago by Mat

This is a ridiculous misusage of the feature.

Unfortunately, it is a bug though.

comment:3 Changed 11 years ago by mlipok

I think I have another example

_test()
Func _test()
	Local $iTEST = 0
	Local $iTEST2 = 0

	For $i = 1 To 4
		($i = 1) ? ($iTEST = $i) : ($iTEST2 = 4 - $i)
		($i = 2) ? ($iTEST = $i) : ($iTEST2 = 4 - $i)
		($i = 3) ? ($iTEST = $i) : ($iTEST2 = 4 - $i)
		($i = 4) ? ($iTEST = $i) : ($iTEST2 = 4 - $i)
		ConsoleWrite('$i = ' & $i & ' $iTEST = ' & $iTEST & ' $iTEST2 = ' & $iTEST2 & @CRLF)
	Next
EndFunc   ;==>_test

Please confirm that this is (or not) the same problem.

comment:4 Changed 11 years ago by mlipok

Here I have another "explantation/suplementar" example:

_test2()
Func _test2()
	Local $iTEST3 = 4
	ConsoleWrite('TEST1 : ' & ((1 = 2) ? ('A') : ('b')) & @CRLF)
	ConsoleWrite('TEST2 : ' & ((2 = 2) ? ('A') : ('b')) & @CRLF)
	ConsoleWrite('TEST3 : ' & ((1 = 3) ? ($iTEST3 = 4) : ($iTEST3 = 2)) & @CRLF)
	ConsoleWrite('TEST4 : ' & ((3 = 3) ? ($iTEST3 = 4) : ($iTEST3 = 2)) & @CRLF)
EndFunc   ;==>_test

comment:5 Changed 11 years ago by anonymous

The documentation clearly indicates that the "arguments" must be expressions. Exit is a statement. An assignment is a statement. A comparison is an expression. So, a=b will be a comparison and not an assignment.

comment:6 Changed 11 years ago by mlipok

The question which therefore is simply a string? String is expression?
[hr]
So the problem is not in the way this feature works, but the description in the documentation is incomplete or is not right.

According to me, a section called "Return Value" is missing here.

some proposal:

Return Value:
Return from Expression1 or Expression2, relative to Return from first conditional Expression

ps.
probably someone describe it better than me ;)

comment:7 Changed 11 years ago by anonymous

plus that would work is an expression:
HotKeySet('some key',Exit)

comment:8 Changed 9 years ago by BrewManNH

  • Resolution set to Works For Me
  • Status changed from new to closed

The problem isn't in the ternary operator, the problem is that everyone is misunderstanding what is going on when using it.

Comment 3 - The results are 100% correct, the problem is that you're expecting ($i = 1) ? ($iTEST = $i) : ($iTEST2 = 4 - $i) to assign the right value to the left variable, that's not what is happening. What's happening is that if $i = 1 then you are COMPARING the right value to the contents of the left variable. The result is a Boolean True or False, there is no assigning of values being done at all. So the consolewrite at the end is always going to show a value of 0 for $iTest and $iTest2 because that is what you set them to at the start of the loop.

Comment 4 - This demonstrates exactly what I was referring to in my reply to the code in Comment 3. The last 2 ternary operations are telling you that because 1 doesn't equal 3, use the second expression's answer, which is going to be FALSE because $iTEST3 does not equal 2, you aren't assigning 2 to $iTEST3, you're comparing it to the value in $iTEST3, which is 4. The next one says that because 3 does equal 3, run the first expression, and because $iTEST3 does equal 4, return TRUE.

As to the OP, the code works as expected to me. Exit isn't an expression, it's a statement keyword and doesn't work as you're expecting it to in the ternary operator. Sorry, but that is how it works and you're using it wrong.
The second example in your original post triggers an error message in AU3Check, but will run as is if you turn off AU3Check before trying to run it. There's nothing wrong in the code, just the syntax checker doesn't understand it. You can bypass the error message by assigning the whole thing to a variable like this.

$Test = (1 < 2) ? MsgBox(0, 0, 0) : ex()

I see no bugs here, just misunderstandings and poor code.

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.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.