Explorar o código

* give a proper error when a rangen appears in a vecn that's not an
array parameter (mantis #15287)

git-svn-id: trunk@14368 -

Jonas Maebe %!s(int64=15) %!d(string=hai) anos
pai
achega
b521f80b13
Modificáronse 3 ficheiros con 26 adicións e 1 borrados
  1. 1 0
      .gitattributes
  2. 6 1
      compiler/nmem.pas
  3. 19 0
      tests/webtbf/tw15287.pp

+ 1 - 0
.gitattributes

@@ -9493,6 +9493,7 @@ tests/webtbf/tw14849.pp svneol=native#text/plain
 tests/webtbf/tw14929a.pp svneol=native#text/plain
 tests/webtbf/tw14929b.pp svneol=native#text/plain
 tests/webtbf/tw14946.pp svneol=native#text/plain
+tests/webtbf/tw15287.pp svneol=native#text/plain
 tests/webtbf/tw15288.pp svneol=native#text/plain
 tests/webtbf/tw1599.pp svneol=native#text/plain
 tests/webtbf/tw1599b.pp svneol=native#text/plain

+ 6 - 1
compiler/nmem.pas

@@ -893,7 +893,12 @@ implementation
          else if is_widestring(left.resultdef) and (tf_winlikewidestring in target_info.flags) then
            exclude(flags,nf_callunique);
 
-         if (not is_packed_array(left.resultdef)) or
+         { a range node as array index can only appear in function calls, and
+           those convert the range node into something else in
+           tcallnode.gen_high_tree }
+         if (right.nodetype=rangen) then
+           CGMessagePos(right.fileinfo,parser_e_illegal_expression)
+         else if (not is_packed_array(left.resultdef)) or
             ((tarraydef(left.resultdef).elepackedbitsize mod 8) = 0) then
            if left.expectloc=LOC_CREFERENCE then
              expectloc:=LOC_CREFERENCE

+ 19 - 0
tests/webtbf/tw15287.pp

@@ -0,0 +1,19 @@
+{ %fail }
+
+program arrayrangeoperator;
+
+{$mode objfpc}{$H+}
+
+uses
+  Classes, SysUtils;
+
+type
+  TArrayOfInteger = array of integer;
+var
+  a, b: TArrayOfInteger;
+begin
+  SetLength(a,10);
+  b:=a[2..4];
+end.
+
+