Switch bug, CaseSense is invalid. Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
XMB-7
Posts: 16
Joined: 08 Jan 2023, 20:58
Contact:

Switch bug, CaseSense is invalid.

Post by XMB-7 » 03 Jun 2023, 12:21

Code: Select all

!T::
{
    test_str := 'a'
    switch(SwitchValue:=test_str, CaseSense:='Off')
    {
        case 'a': MsgBox('1')
        case 'b': MsgBox('2')
        default: MsgBox('0')
    }
}
When triggering the above hotkey, 0 always pops up.
Only with `CaseSense:='Off'` removed, 1 would pop up as expected.

image.png
image.png (73.84 KiB) Viewed 593 times

[Mod action: Topic moved from "Bug Reports" since it is not a bug.]

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Switch bug, CaseSense is invalid.

Post by swagfag » 03 Jun 2023, 13:17

ure misusing the parentheses, passing the value of whichever rightmost sub-expression gets evaluated last to switch's first parameter. get rid of them

XMB-7
Posts: 16
Joined: 08 Jan 2023, 20:58
Contact:

Re: Switch bug, CaseSense is invalid.

Post by XMB-7 » 03 Jun 2023, 22:07

Does the switch statement still use the v1 syntax? I only learned v2, and just thought anything that accepts arguments should be considered a function and all arguments can be enclosed in parentheses.
If so, when implementing something like `switch(SwitchValue:=test_str, CaseSense:='Off')`, it would be better for the interpreter to report an error.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Switch bug, CaseSense is invalid.  Topic is solved

Post by swagfag » 03 Jun 2023, 22:56

it uses whatever syntax is documented, which clearly isnt the one u seem to be thinking of

switch is a built-in keyword, a control-flow statement. not a function, not a command nor anything else u might have thought it was

the interpreter cant report an error, because this usage is not erroneous

Post Reply

Return to “Ask for Help (v2)”