"Double-deref" not working in Keysharp.

Issue #65 closed
Winter Laite created an issue

ISSUE

Variables as described on dynamic variables docs page do not function as in AHK.

working ahk script
target := 42
second := "target"
MsgBox(second)   ; Normal (single) variable reference => target
MsgBox(%second%)  ; Double-deref => 42

With AHK the MsgBoxes display as per the comments. With Keysharp both display “target”.

Comments (7)

  1. Matt Feemster repo owner

    It appears that I attempted to implement this, but misunderstood the documentation. After revisiting the documentation, tell me if this is correct:

    Scenario 1: what you listed above, where the variable is referenced by itself, and thus dereferences two levels deep: second => “target”, then target => 42

    Scenario 2: the variable is used in conjunction with another value, to access a variable or property of an object, and thus dereferences only one level deep: %A_Index% => 1, 2 or 3, then concatenated with MyArray

    MyArray1 := "A"
    MyArray2 := "B"
    MyArray3 := "C"
    Loop 3
        MsgBox MyArray%A_Index%  ; Shows A, then B, then C.
    

    class myclass
    {
      mymember1 := 123
    }
    
    c := new myclass()
    val := 1
    MsgBox(c.mymember%val%) ; Shows 123
    

    \%val% => 1, then concatenated with mymember

    So by itself, it goes two levels deep, but when being used as a member and/or with a partial variable name, it goes one level deep.

  2. Winter Laite reporter
    class myclass
    {
      mymember1 := 123
    }
    
    c := myclass()
    val := 1
    MsgBox(c.mymember%val%) ; Shows 123
    

    (Using the ‘new’ keyword here will throw on error)

    I believe your explanation is right. You might consider this also:

    MyArray1 := "A"
    MyArray2 := "B"
    MyArray3 := "C"
    MyArray4 := MyArray1
    ;MyArray4 := %MyArray1% ; ERROR: Variable not found. Specifically: A
    Loop 4
        MsgBox MyArray%A_Index%  ; Shows A, then B, then C, then A
    

  3. Matt Feemster repo owner

    Sounds good. The first snippet was just pseudo code to illustrate the point. Sounds like we agree so I’ll get going on it.

  4. Winter Laite reporter

    All unit tests confirmed, also when modified to v2-like syntax. Marking resolved and closing. Excellent work, thank you!

  5. Log in to comment