瀏覽代碼

* dont' allow assignments to array of const, resolves #41230

florian 3 月之前
父節點
當前提交
4cae231a52
共有 2 個文件被更改,包括 12 次插入1 次删除
  1. 1 1
      compiler/nld.pas
  2. 11 0
      tests/webtbf/tw41230.pp

+ 1 - 1
compiler/nld.pas

@@ -746,7 +746,7 @@ implementation
           maybe_call_procvar(right,true);
           maybe_call_procvar(right,true);
 
 
         { assignments to formaldefs and open arrays aren't allowed }
         { assignments to formaldefs and open arrays aren't allowed }
-        if is_open_array(left.resultdef) then
+        if is_open_array(left.resultdef) or is_array_of_const(left.resultdef) then
           begin
           begin
             CGMessage(type_e_assignment_not_allowed);
             CGMessage(type_e_assignment_not_allowed);
             result:=cerrornode.create;
             result:=cerrornode.create;

+ 11 - 0
tests/webtbf/tw41230.pp

@@ -0,0 +1,11 @@
+{ %fail }
+program app;
+{$mode objfpc}
+
+procedure test(a: array of const);
+begin
+  a := [1, 2, 3];
+end;
+
+begin
+end.