Răsfoiți Sursa

* fix for Mantis #37272: also allow the empty set for dynamic array parameters; Delphi probably started to allow that together with array constructors.
+ added tests

git-svn-id: trunk@45706 -

svenbarth 5 ani în urmă
părinte
comite
eaa2a2006c
5 a modificat fișierele cu 53 adăugiri și 1 ștergeri
  1. 2 0
      .gitattributes
  2. 11 0
      compiler/defcmp.pas
  3. 6 1
      compiler/ncnv.pas
  4. 18 0
      tests/webtbf/tw37272b.pp
  5. 16 0
      tests/webtbs/tw37272a.pp

+ 2 - 0
.gitattributes

@@ -16497,6 +16497,7 @@ tests/webtbf/tw36720.pp svneol=native#text/pascal
 tests/webtbf/tw3680.pp svneol=native#text/plain
 tests/webtbf/tw36975.pp svneol=native#text/pascal
 tests/webtbf/tw3716.pp svneol=native#text/plain
+tests/webtbf/tw37272b.pp svneol=native#text/pascal
 tests/webtbf/tw3738.pp svneol=native#text/plain
 tests/webtbf/tw3740.pp svneol=native#text/plain
 tests/webtbf/tw3790.pp svneol=native#text/plain
@@ -18340,6 +18341,7 @@ tests/webtbs/tw3719.pp svneol=native#text/plain
 tests/webtbs/tw3721.pp svneol=native#text/plain
 tests/webtbs/tw37218.pp svneol=native#text/pascal
 tests/webtbs/tw37228.pp svneol=native#text/plain
+tests/webtbs/tw37272a.pp svneol=native#text/pascal
 tests/webtbs/tw3742.pp svneol=native#text/plain
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain

+ 11 - 0
compiler/defcmp.pas

@@ -1233,6 +1233,17 @@ implementation
                               eq:=te_convert_l1;
                            end;
                       end;
+                    setdef :
+                      begin
+                        { special case: an empty set constant is compatible as
+                          well }
+                        if not assigned(tsetdef(def_from).elementdef)
+                            and (fromtreetype=setconstn) then
+                          begin
+                            doconv:=tc_arrayconstructor_2_dynarray;
+                            eq:=te_convert_l1;
+                          end;
+                      end;
                     else
                       ;
                   end;

+ 6 - 1
compiler/ncnv.pas

@@ -2007,7 +2007,12 @@ implementation
         elemnode:tarrayconstructornode;
       begin
         { assignment of []? }
-        if (left.nodetype=arrayconstructorn) and not assigned(tarrayconstructornode(left).left) then
+        if (
+              (left.nodetype=arrayconstructorn) and
+              not assigned(tarrayconstructornode(left).left)
+            ) or
+              is_emptyset(left)
+            then
           begin
             result:=cnilnode.create;
             exit;

+ 18 - 0
tests/webtbf/tw37272b.pp

@@ -0,0 +1,18 @@
+{ %FAIL }
+
+program tw37272b;
+
+{ note: there is a tw37272a in webtbs }
+
+{$mode objfpc}
+
+type
+  TA1 = array of integer;
+
+procedure Test(A: integer; const B: TA1 = [1]);
+begin end;
+
+begin
+  Test(1, []);
+  Test(1);
+end.

+ 16 - 0
tests/webtbs/tw37272a.pp

@@ -0,0 +1,16 @@
+program tw37272a;
+
+{ note: there is a tw37272b in webtbf }
+
+{$mode objfpc}
+
+type
+  TA1 = array of integer;
+
+procedure Test(A: integer; const B: TA1 = []);
+begin end;
+
+begin
+  Test(1, []);
+  Test(1);
+end.