Is it possible to pass a dummy parameter to a user-defined operator, with no expectation that it be referenced?

The following test program compiles OK but fails at runtime with an error 217 on all platforms if the record is empty. It works if it contains a variant, but not reliably with other types.

program test;

{$mode objfpc}{$H+}

type    t1= array of integer;
        r_= record
//              x: variant
            end;

var     a1: t1;
        reduce: r_ = ();


procedure print(const a: t1);

var     i: integer;

begin
  for i := Low(a) to High(a) do
    Write(a[i], ' ');
  WriteLn
end { print } ;


operator + (const r: r_; const a: t1) s: variant;

var     i: integer;

begin
  s := 0;
  for i := Low(a) to High(a) do
    s += a[i]
end { + } ;


begin
//  a1 := t1([1,2,3,4,5]);      Doesn't work without tuple support
  SetLength(a1, 5);
  a1[0] := 1;
  a1[1] := 2;
  a1[2] := 3;
  a1[3] := 4;
  a1[4] := 5;
  WriteLn('a1:');
  print(a1);
  WriteLn('+/ a1:');
  WriteLn(reduce + a1);
  WriteLn
end.

This is of no particular importance, I'm just exploring capabilities.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to