Prechádzať zdrojové kódy

* prohibit static array constants inside dynamic array constants for Delphi modes
+ added test

git-svn-id: trunk@39045 -

svenbarth 7 rokov pred
rodič
commit
dcdb151add
3 zmenil súbory, kde vykonal 23 pridanie a 0 odobranie
  1. 1 0
      .gitattributes
  2. 10 0
      compiler/ngtcon.pas
  3. 12 0
      tests/test/tarray17.pp

+ 1 - 0
.gitattributes

@@ -12504,6 +12504,7 @@ tests/test/tarray13.pp svneol=native#text/pascal
 tests/test/tarray14.pp svneol=native#text/pascal
 tests/test/tarray15.pp svneol=native#text/pascal
 tests/test/tarray16.pp svneol=native#text/pascal
+tests/test/tarray17.pp svneol=native#text/pascal
 tests/test/tarray2.pp svneol=native#text/plain
 tests/test/tarray3.pp svneol=native#text/plain
 tests/test/tarray4.pp svneol=native#text/plain

+ 10 - 0
compiler/ngtcon.pas

@@ -1197,6 +1197,16 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                   end
                 else
                   begin
+                    { Delphi does not correctly parse static array constants
+                      inside dynamic array constants. Additionally static and
+                      dynamic array constants use different syntaxes ("(...)"
+                      vs. "[...]"), so it's safer we simply disallow it until
+                      the Delphi developers clears up this mess if ever }
+                    if (m_delphi in current_settings.modeswitches) and
+                        (def.elementdef.typ=arraydef) and
+                        not is_dynamic_array(def.elementdef) then
+                      Message(parser_e_no_static_array_const_in_dynarray_const);
+
                     if fsym.varspez=vs_const then
                       sectype:=sec_rodata
                     else

+ 12 - 0
tests/test/tarray17.pp

@@ -0,0 +1,12 @@
+{ %FAIL }
+
+program tarray17;
+
+{$mode delphi}
+
+var
+  v1: array of array[0..2] of LongInt = [(1, 2, 3), (4, 5, 6)];
+
+begin
+
+end.