AArhin / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Bad codegen for dynamic array of records #278

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
type
  TRec = record
    name: string;
    id: integer;
    //why doesn't constructor syntax work here?!?
    class function Create(id: integer; name: string): TRec;
  end;

class function TRec.Create(id: integer; name: string): TRec;
begin
  result.id := id;
  result.name := name;
end;

procedure Testing;
var
  recs: array of TRec;
begin
  recs.add(TRec.Create(1, 'A'));
  print(recs[0].name);
  print(format('%s', [recs[0].name]));
end;

testing;

Original issue reported on code.google.com by masonwhe...@gmail.com on 10 Jun 2012 at 1:19

GoogleCodeExporter commented 9 years ago
"constructor" isn't accepted for now because the syntax introduced in Delphi 
for records is ambiguous and has problematic cases, as it can be called on 
values and not just to create a new record (so it's a mix between a function 
and a procedure with a var param that also accepts const params).
How and if that should be fixed hasn't been decided, especially as there have 
been rumors it could be changed/fixed in the "next gen" Delphi compiler, 
including possible automatic invocation of the default constructor...

So since "constructor" functionality can be covered by class function syntax in 
and unambiguous, support for it is currently in stasis pending further info 
from Embarcadero.

Original comment by zar...@gmail.com on 19 Jun 2012 at 7:34

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1502.

Original comment by zar...@gmail.com on 19 Jun 2012 at 7:53