X-Sharp / XSharpPublic

Public repository for the source code for the XSharp Compiler, Runtime, Project System and Tools.
Apache License 2.0
113 stars 38 forks source link

Add support for late bound indexed property access #1455

Open RobertvanderHulst opened 6 months ago

RobertvanderHulst commented 6 months ago

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).

cpyrgas commented 6 months ago

There already exists a test for this in the suite, C706