[v2.beta.3] !':: Send("'") error Topic is solved

Report problems with documented functionality
john_c
Posts: 493
Joined: 05 May 2017, 13:19

[v2.beta.3] !':: Send("'") error

Post by john_c » 10 Jan 2022, 00:58

Not really sure whether a bug or not:

Code: Select all

#SingleInstance Force

A_IconTip := "foo"

!':: Send("'")
gives me an error message.

If I remove A_IconTip line, it seems to work fine.

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: [v2.beta.3] !':: Send("'") error

Post by neogna2 » 10 Jan 2022, 03:33

Seems this only happens if (1) there is at least one prior line of code, (2) the hotkey is !' and (3) the hotkey action sends or does something with ' or " . Another example of the same issue

Code: Select all

a := 1
!':: MsgBox '"'

john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: [v2.beta.3] !':: Send("'") error

Post by john_c » 10 Jan 2022, 17:13

A workaround that works for me is

Code: Select all

!':: Send(Chr(39))

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: [v2.beta.3] !':: Send("'") error

Post by neogna2 » 11 Jan 2022, 05:50

adding braces to the hotkey also avoids the error

Code: Select all

a := 1
!':: 
{
    Send("'")
}

john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: [v2.beta.3] !':: Send("'") error

Post by john_c » 01 Feb 2022, 19:52

A note for myself: the cleanest workaround is to add a dollar sign. $!':: Send("'")

Warvis
Posts: 2
Joined: 03 Feb 2022, 14:12

Re: [v2.beta.3] !':: Send("'") error

Post by Warvis » 03 Feb 2022, 15:05

I had this effect recently after switching to ahk v2, and transferring some older simple hotkey scripts:
It seems this is a side effect of the more relaxed line-continuation syntax in v2 (which I really appreciate).

With ahk2.b3 the errormsg tells you what it is parsing:

Code: Select all

parseexclamation.ahk (5) : ==> Missing """
     Specifically: a := 1 !':: MsgBox '"'
The alt-modifier from the hotkey is parsed as logical-not on a continued line for the assignment expression. This happens with every statement which can have a parameter or expression on the preceding line (like a return from the autostart section).
Unfortunately we don't seem to have an explicit 'end of statement' symbol (like the semicolon in js/lua) to resolve this ambiguity, and I think the issue here is the switch from "script syntax" to "hotkey syntax".
What I did was putting a "#HotIf" statement before the hotkey definitions, to stop the continuation parsing.

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: [v2.beta.3] !':: Send("'") error

Post by neogna2 » 09 Feb 2022, 05:07

Warvis wrote:
03 Feb 2022, 15:05
It seems this is a side effect of the more relaxed line-continuation syntax in v2
...
The alt-modifier from the hotkey is parsed as logical-not on a continued line for the assignment expression.
...
the issue here is the switch from "script syntax" to "hotkey syntax".
Seems true. We can trigger the same error with the + (Shift key) hotkey modifier.

Code: Select all

a := 1
+'::  Send("'")
So in other words v2.beta3 confuses the hotkey modifier + with the expression-operator + in the role of line continuation operator.
As you say, AutoHotkey doesn't have an end of expression symbol. So there must be some more complex what-kind-of-operator-is-the-!-or+-symbol-in-that-position-analyzing code that goes awry in this case.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [v2.beta.3] !':: Send("'") error

Post by Helgef » 09 Apr 2022, 02:38

See :arrow: Continuation operator.
It seems that the possibility of this happening was considered but not deemed important enough to handle,

Code: Select all

// Closing quote was found so "::" is probably inside a literal string of an
// expression (further checking seems unnecessary given the fairly extreme
// rarity of using '"' as a key in a hotkey definition).
src: script.cpp (IsSOLContExpr())
For " and ' hotkeys which starts with a modifier that is also an operator you can avoid the problem by not using a one-line hotkey (not needed if the line doesn't contain a matching " or ')

Example,

Code: Select all

; ok:
msgbox 
!'::{
('"')
}
; ok
msgbox 
!'::("") ; no matching '

; not ok
msgbox 
!"::("") ; matching "
Cheers.

john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: [v2.beta.3] !':: Send("'") error

Post by john_c » 23 Jun 2022, 13:36

Hello, Helgef. Sorry for a late reply. Thanks for your research.

This is bad. I hoped that AHK2 will be free of weird inconsistencies, because it was declared as one of its primary goals, but it seems despite some inconsistencies are now gone, other ones are introduced.

Having a more relaxed line-continuation syntax is not a good reason to introduce inconsistencies, if you ask me. Dealing with inconsistencies may look as something "not that really problematic" or it may look even funny, but only if user works with AHK really often. Otherwise, no...

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2.beta.3] !':: Send("'") error

Post by lexikos » 24 Jun 2022, 02:21

The comment Helgef quoted can be found in the v1 source code. The issue can also easily be demonstrated in v1:

Code: Select all

MsgBox
+":: Send "
The only reason this can occur for !':: or +':: in v2 but not v1 is that v1 does not allow single quotes for quoted strings.

john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: [v2.beta.3] !':: Send("'") error

Post by john_c » 24 Jun 2022, 05:23

The only reason this can occur for !':: or +':: in v2 but not v1 is that v1 does not allow single quotes for quoted strings.
lexikos, I think the reason I was so surprised that !':: Send("'") doesn't work is because the new send is a function and not a command, and so its quotation mark is clearly a function argument, and so it is clearly isolated from anything else, and so I haven't expected it may cause troubles.

The "old" send is not a function but a command (Send " instead Send("'")), and so it wasn't surprise for me that sending special characters like double quotation mark may be problematic sometimes. (In Send ", the quotation mark is simply separated by a space, so we don't consider it as something really isolated from the rest of the code.)

In other words, when we use the new send, we have a higher degree of expectations about how is it reliable to send special characters, and in this particular case, these expectations failed.

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2.beta.3] !':: Send("'") error  Topic is solved

Post by lexikos » 13 Jul 2022, 04:00

v2.0-beta.7 implements a simpler, more generally appropriate rule:

If the line begins with valid hotkey syntax, it is not line continuation.

Key names are not required to be valid, which simplifies parsing (such as for syntax highlighters and language servers) and allows us to add key names later without risk of changing continuation behaviour.

There is no guessing about how to interpret the line, making special cases for specific hotkeys, scanning for quote marks or trying to figure out what is or isn't a valid expression. After much thought, I could only come up with a single case which could potentially be interpreted as both a valid expression continuation and a valid hotkey:

Code: Select all

MsgBox
+!'::'
The result of applying ! to a non-empty non-numeric string is always 0, and the result of applying + to 0 is 0, so the MsgBox shows 0. The odds of someone writing this and not intending it to be a hotkey are very slim.

Post Reply

Return to “Bug Reports”