AArhin / dwscript

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

Impossible to assign a default empty array to an array parameter #300

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
type
   TMyClass = class
      name: string;
   end;

   TMyClasses = array of TMyClass;

procedure DoSomething(data: TMyClasses = []); //fails
procedure DoSomething(data: TMyClasses = nil); //also fails

One or both of these should compile and work as expected.

Original issue reported on code.google.com by masonwhe...@gmail.com on 10 Oct 2012 at 12:08

GoogleCodeExporter commented 9 years ago
And while we're on the subject, why does trying to assign a default value to a 
const param fail with a compiler error?

Original comment by masonwhe...@gmail.com on 10 Oct 2012 at 12:11

GoogleCodeExporter commented 9 years ago
> procedure DoSomething(data: TMyClasses = []); //fails

Now supported.
Not sure about supporting the nil form, dynamic arrays in DWS distinguish and 
empty array from a nil pointer, so that would have to go under some Delphi 
compatibility option.

> why does trying to assign a default value to a const param fail with a 
compiler error?

I'm not sure what the limitation was exactly, though it was a long time ago, so 
the limitation is probably obsolete, opened as Issue #302

Original comment by zar...@gmail.com on 17 Oct 2012 at 3:15