Recent

Author Topic: procedure variables with advanced records  (Read 852 times)

creaothceann

  • Jr. Member
  • **
  • Posts: 89
procedure variables with advanced records
« on: September 19, 2018, 11:01:15 am »
This doesn't work:

Code: Pascal  [Select]
  1. program ProgramName;  {$MODESWITCH AdvancedRecords}
  2.  
  3.  
  4. type
  5.         T_ProcVar = procedure;
  6.  
  7.  
  8.         T = record
  9.                 private
  10.                 procedure _Proc0;
  11.                 procedure _Proc1;
  12.                 procedure _Test(const p : T_ProcVar);
  13.                 public
  14.                 procedure Run;
  15.                 end;
  16.  
  17.  
  18. var
  19.         tmp : T;
  20.  
  21.  
  22. procedure T._Proc0;  begin  end;
  23. procedure T._Proc1;  begin  end;
  24.  
  25.  
  26. procedure T._Test(const p : T_ProcVar);
  27. begin
  28. p;
  29. end;
  30.  
  31.  
  32. procedure T.Run;
  33. begin
  34. _Test(@_Proc0);        // ← error
  35. end;
  36.  
  37.  
  38. begin
  39. tmp.Run;
  40. end.

Quote
Compile Project, Target: AdvRec.exe: Exit code 1, Errors: 1, Hints: 1
AdvRec.lpr(34,14) Error: Incompatible type for arg no. 1: Got "<procedure variable type of procedure;Register>", expected "PROGRAMNAME.<procedure variable type of procedure;Register>"
AdvRec.lpr(26,13) Hint: Found declaration: _Test(const T_ProcVar);

Is this just a matter of syntax?

Changing "procedure;" to "procedure of object;" results in this message:

Quote
AdvRec.lpr(34,14) Error: Incompatible type for arg no. 1: Got "<procedure variable type of procedure;Register>", expected "<procedure variable type of procedure of object;Register>"

Pascal

  • Hero Member
  • *****
  • Posts: 783
Re: procedure variables with advanced records
« Reply #1 on: September 19, 2018, 11:28:26 am »
Could be a bug!

Quote
Got "<procedure variable type of procedure;Register>", expected "PROGRAMNAME.<procedure variable type of procedure;Register>"
Expected type has leading "PROGRAMNAME." which makes no sense. Except that the type is identical.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Bart

  • Hero Member
  • *****
  • Posts: 3167
    • Bart en Mariska's Webstek
Re: procedure variables with advanced records
« Reply #2 on: September 19, 2018, 12:06:35 pm »
Maybe https://www.freepascal.org/docs-html/ref/refse17.html help?
See the "is nested" part.

Bart

creaothceann

  • Jr. Member
  • **
  • Posts: 89
Re: procedure variables with advanced records
« Reply #3 on: September 19, 2018, 12:34:05 pm »
Maybe https://www.freepascal.org/docs-html/ref/refse17.html help?
See the "is nested" part.

Code: [Select]
{$MODESWITCH AdvancedRecords}
{$MODESWITCH NestedProcVars}


type
        T_ProcVar = procedure is nested;

Quote
Compile Project, Target: AdvRec.exe: Exit code 1, Errors: 1, Hints: 1
AdvRec.lpr(38,14) Error: Incompatible type for arg no. 1: Got "<procedure variable type of procedure;Register>", expected "<procedure variable type of procedure is nested;Register>"
AdvRec.lpr(30,13) Hint: Found declaration: _Test(const T_ProcVar);

(and no, "of object is nested" isn't possible ::) )

bytebites

  • Full Member
  • ***
  • Posts: 164
Re: procedure variables with advanced records
« Reply #4 on: September 19, 2018, 03:35:27 pm »
Original code works in Delphi-mode and trunk-compiler

creaothceann

  • Jr. Member
  • **
  • Posts: 89
Re: procedure variables with advanced records
« Reply #5 on: September 19, 2018, 05:20:06 pm »
Mmmh, so it seems. Looks like a bug then.