XSharpPublic icon indicating copy to clipboard operation
XSharpPublic copied to clipboard

Add support for late bound indexed property access

Open RobertvanderHulst opened this issue 10 months ago • 1 comments

The following code compiles fine. However if you replace the type in the declaration of Foo with USUAL then the code fails at runtime.

using System.Collections.Generic
FUNCTION Start() AS VOID
    local oFoo as Foo
    oFoo := Foo{}
    oFoo:Bar["abc"] := "def"
    ? oFoo:Bar["abc"]
    ? oFoo:_Bar["abc"]

CLASS Foo
    public _bar as Dictionary<usual, usual>
    constructor
        _bar := Dictionary<usual, usual>{}
    PROPERTY Bar[index as usual] as usual
    get
        return _bar[index]
    end get
    set
          _bar[index] := value
    end set
    end property
end class

The compiler should translate to something like

IVarPutCollection(oFoo, "Bar",<Object>{"abc"},"def")
IVarGetCollection(oFoo, "Bar",<Object>{"abc"})
IVarGetCollection(oFoo, "_Bar",<Object>{"abc"})

Both functions should accept an array of indices Inside IVarGetCollection and IVarPutCollection the runtime should check to see if Bar is a normal IVar that returns an Array or if it is an indexed property. And of course, Bar could also be a field that has an indexer (like the public _bar in the example).

RobertvanderHulst avatar Apr 23 '24 10:04 RobertvanderHulst