diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 2e9fa4a74c..996956766c 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -1988,7 +1988,7 @@ implementation end; var - elem : tnode; + constr : tnode; para : tcallparanode; isarrconstrl, isarrconstrr : boolean; @@ -2017,14 +2017,14 @@ implementation if isarrconstrl then begin index:=0; - elem:=tarrayconstructornode(left).left; - tarrayconstructornode(left).left:=nil; + constr:=left; + left:=nil; end else begin index:=high(asizeint); - elem:=tarrayconstructornode(right).left; - tarrayconstructornode(right).left:=nil; + constr:=right; + right:=nil; end; { we use the fact that insert() caps the index to avoid a copy } @@ -2033,7 +2033,7 @@ implementation ccallparanode.create( aktassignmentnode.left.getcopy, ccallparanode.create( - elem,nil))); + constr,nil))); result:=cinlinenode.create(in_insert_x_y_z,false,para); include(aktassignmentnode.assignmentnodeflags,anf_assign_done_in_right); diff --git a/tests/webtbf/tw40725.pp b/tests/webtbf/tw40725.pp new file mode 100644 index 0000000000..12e633219b --- /dev/null +++ b/tests/webtbf/tw40725.pp @@ -0,0 +1,30 @@ +{ %FAIL } + +program tw40725; + +{$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. +