Array of records in Java and assigned()

Hi
The last stable release (.2629) was working fine with this code :

namespace consoleapplication22;

uses
  java.util;

type
  T_R nested in T_Obj = record
    public
      Id : Integer ;
  end;
  
  T_Obj = class
    public
      arr  : array of T_R;
      arr2 : array of T_R;
    public
      method Init ;
      begin
        arr2 := new T_R[1];
        arr2[0].Id := 1 ;
        // SetLength
        arr := array of T_R(java.lang.reflect.Array.newInstance( typeOf(T_R), 1 )) ;
        if not assigned(arr[0]) then
          arr[0] := new T_R(); // should go here
        arr[0].Id := 1 ;
      end;
  end;
  
  Program = class
  public
    class method Main(args: array of String): Int32;
    begin
      var o := new T_Obj();
      o.Init;
    end;
  end;
end.

New stable (2635) fails checking assigned() condition, assuming that arr[0] is allocated and new T_R() is not needed. The code fails to set arr[0].Id. Declaring T_R as a class fixes assigned() check.

Is this a bug or a change by design (so we need to change the declaration)?
Artur

Hrmm this looks like a regression. Let me create a bug.

This turned out to be an optimization for assigned(x) → true for valuetypes that should never have hit on Cooper. Fixed!

3 Likes