[VFP] cannot use the arr[ind1][ind2] syntax to access array members in VFP dialect
Following results to a runtime exception:
FUNCTION Start( ) AS VOID
DIMENSION arr(5, 5)
arr[2,3] := 123 // ok
? arr[2,3]
arr[1][4] := 456 // exception
? arr[1][4]
System.NullReferenceException
Object reference not set to an instance of an object.
Callstack :
XSharp.__Usual.[Method XSharp.__Usual.GetIndexedProperty(parType:System.Type):System.Reflection.PropertyInfo]
XSharp.__Usual.[Accessor XSharp.__Usual.set_Item(index:System.Int32, value:XSharp.__Usual):System.Void]
[Method XSharpFoxPro1_tester.Exe.Functions.Start():System.Void] : C:\VIDE\Projects\ONE\Applications\XSharpFoxPro1_tester\Prg\FoxProTest.prg : 7
This fails because the internal implementation of the FoxPro Array class is single-dimensional. I had to do that because FoxPro arrays can be redimensioned without losing their contents. An array arr(3,4) can be redimensioned to arr(4,3) without losing the values inside the array.
arr[1][4] := 456
gets translated by the compiler to
uElement := arr[1]
uElement[4] := 456
But, foxpro arrays multi-dimensional arrays can also be accessed with a single dimension, so array element[1] returns a NIL, so you cannot retrieve subelement 4. To support this, we would have to redesign the FoxPro array class, so it is multi-dimensional like the VO array. But we would then have a problem with the syntax arr[1] because that would return a subarray and not a single element.
We could change the compiler to convert arr[1][4] to arr[1,4] but that could cause other problems when for example arr is a dictionary.
That was also my thought, to make the compiler convert [][] to [,] for the foxpro dialect. Can't this be done for all but strongly items items? And hande [][] as [,] only when the identifier is of unknown type.
I will see if I can do that.