소스 검색

* reject the default Create array constructor if used on a variable instead of a type
+ added test

git-svn-id: trunk@46279 -

svenbarth 5 년 전
부모
커밋
e4ec420bf5
3개의 변경된 파일30개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 16 6
      compiler/pexpr.pas
  3. 13 0
      tests/test/tarrconstr8.pp

+ 1 - 0
.gitattributes

@@ -14375,6 +14375,7 @@ tests/test/tarrconstr4.pp svneol=native#text/pascal
 tests/test/tarrconstr5.pp svneol=native#text/pascal
 tests/test/tarrconstr6.pp svneol=native#text/pascal
 tests/test/tarrconstr7.pp svneol=native#text/pascal
+tests/test/tarrconstr8.pp svneol=native#text/pascal
 tests/test/tasm1.pp svneol=native#text/plain
 tests/test/tasm10.pp svneol=native#text/plain
 tests/test/tasm10a.pp svneol=native#text/plain

+ 16 - 6
compiler/pexpr.pas

@@ -2485,16 +2485,26 @@ implementation
                            begin
                              if not try_type_helper(p1,nil) then
                                begin
-                                 if pattern='CREATE' then
+                                 if p1.nodetype=typen then
                                    begin
-                                     consume(_ID);
-                                     p2:=parse_array_constructor(tarraydef(p1.resultdef));
-                                     p1.destroy;
-                                     p1:=p2;
+                                     if pattern='CREATE' then
+                                       begin
+                                         consume(_ID);
+                                         p2:=parse_array_constructor(tarraydef(p1.resultdef));
+                                         p1.destroy;
+                                         p1:=p2;
+                                       end
+                                     else
+                                       begin
+                                         Message2(scan_f_syn_expected,'CREATE',pattern);
+                                         p1.destroy;
+                                         p1:=cerrornode.create;
+                                         consume(_ID);
+                                       end;
                                    end
                                  else
                                    begin
-                                     Message2(scan_f_syn_expected,'CREATE',pattern);
+                                     Message(parser_e_invalid_qualifier);
                                      p1.destroy;
                                      p1:=cerrornode.create;
                                      consume(_ID);

+ 13 - 0
tests/test/tarrconstr8.pp

@@ -0,0 +1,13 @@
+{ %FAIL }
+
+program tarrconstr8;
+
+type
+  TLongIntArray = array of LongInt;
+
+var
+  arr: TLongIntArray;
+begin
+  // Create *must* be used on a type
+  arr := arr.Create(1, 2);
+end.