FunctionReferences: the + [] operator on array of "reference to procedure" doesn't check the parameter list in mode Delphi
Summary
The + [] operator on array of "reference to procedure" doesn't check the parameter list in mode Delphi. This happens only in mode Delphi and only with the + operator. The normal assignment or objfpc mode works well (=show a compiler error).
System Information
- Operating system: Windows
- Processor architecture: x86-64
- Compiler version: trunk i386
- Device: Computer
Steps to reproduce
See the example project
Example Project
program Project1;
{$mode delphi}
{$ModeSwitch functionreferences}
type
TMyProc = reference to procedure(const A: Integer; const B: string);
TMyProcArray = array of TMyProc;
function GetArray: TMyProcArray;
procedure MyProc(const A: TObject);
begin
end;
begin
//Result := [MyProc]; // compiler error -> OK
Result := Result + [MyProc]; // NO COMPILER ERROR -> BUG
end;
var
A: TMyProcArray;
P: TMyProc;
begin
A := GetArray;
for P in A do
P(1, '');
end.
What is the current bug behavior?
The project compiles and shows an access violation during runtime.
What is the expected (correct) behavior?
A compiler error:
project1.lpr(16,13) Error: Incompatible types: got "{Array Of Const/Constant Open} Array of MyProc(const TObject) is nested;" expected "TMyProcArray"
should be shown and the code should not compile.