Browse Source

* ensure that Insert() of a single element into a dynamic array is typechecked in a way that the user is notified of errors
+ added test

Sven/Sarah Barth 1 year ago
parent
commit
61397d40ae
2 changed files with 24 additions and 1 deletions
  1. 5 1
      compiler/ninl.pas
  2. 19 0
      tests/tbf/tb0298.pp

+ 5 - 1
compiler/ninl.pas

@@ -5541,7 +5541,11 @@ implementation
                      datan:=caddrnode.create_internal(ctemprefnode.create(datatemp));
                      datan:=caddrnode.create_internal(ctemprefnode.create(datatemp));
                    end
                    end
                  else
                  else
-                   datan:=caddrnode.create_internal(ctypeconvnode.create_internal(firstn,tarraydef(second).elementdef));
+                   begin
+                     datan:=firstn;
+                     inserttypeconv(datan,tarraydef(second).elementdef);
+                     datan:=caddrnode.create_internal(datan);
+                   end;
                  datacountn:=cordconstnode.create(1,sizesinttype,false);
                  datacountn:=cordconstnode.create(1,sizesinttype,false);
                end;
                end;
              procname:='fpc_dynarray_insert';
              procname:='fpc_dynarray_insert';

+ 19 - 0
tests/tbf/tb0298.pp

@@ -0,0 +1,19 @@
+{ %FAIL }
+
+program tb0298;
+
+{$mode delphi}
+{$modeswitch functionreferences}
+
+type
+  TMyProc = reference to procedure(aArg: LongInt);
+
+procedure Test(aArg: TObject);
+begin
+end;
+
+var
+  arr: array of TMyProc;
+begin
+  Insert(Test, arr, 0);
+end.