Pārlūkot izejas kodu

* getting the length of a string means that it has to be
valid and marks it as really read (mantis #8264)

git-svn-id: trunk@6327 -

Jonas Maebe 18 gadi atpakaļ
vecāks
revīzija
674660d53b
4 mainītis faili ar 42 papildinājumiem un 2 dzēšanām
  1. 2 0
      .gitattributes
  2. 3 2
      compiler/ninl.pas
  3. 15 0
      tests/webtbf/tw8264a.pp
  4. 22 0
      tests/webtbs/tw8264.pp

+ 2 - 0
.gitattributes

@@ -7159,6 +7159,7 @@ tests/webtbf/tw8150c.pp svneol=native#text/plain
 tests/webtbf/tw8150e.pp svneol=native#text/plain
 tests/webtbf/tw8150f.pp svneol=native#text/plain
 tests/webtbf/tw8150g.pp svneol=native#text/plain
+tests/webtbf/tw8264a.pp svneol=native#text/plain
 tests/webtbf/uw0744.pp svneol=native#text/plain
 tests/webtbf/uw0840a.pp svneol=native#text/plain
 tests/webtbf/uw0840b.pp svneol=native#text/plain
@@ -8023,6 +8024,7 @@ tests/webtbs/tw8222a.pp svneol=native#text/plain
 tests/webtbs/tw8222b.pp svneol=native#text/plain
 tests/webtbs/tw8229.pp svneol=native#text/plain
 tests/webtbs/tw8232.pp svneol=native#text/plain
+tests/webtbs/tw8264.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 3 - 2
compiler/ninl.pas

@@ -1583,8 +1583,9 @@ implementation
 
               in_length_x:
                 begin
-                  if not(is_special_array(left.resultdef)) or
-                    (left.resultdef.typ=orddef) then
+                  if ((left.resultdef.typ=arraydef) and
+                      not is_special_array(left.resultdef)) or
+                     (left.resultdef.typ=orddef) then
                     set_varstate(left,vs_read,[])
                   else
                     set_varstate(left,vs_read,[vsf_must_be_valid]);

+ 15 - 0
tests/webtbf/tw8264a.pp

@@ -0,0 +1,15 @@
+{ %fail }
+{ %opt=-Sew }
+
+{$mode delphi}
+
+function calclength1: integer;
+var
+  a: array of byte;
+begin
+  result := length(a);
+end;
+
+
+begin
+end.

+ 22 - 0
tests/webtbs/tw8264.pp

@@ -0,0 +1,22 @@
+{ %opt=-Sen }
+{$mode delphi}
+
+function calclength1(const s1: shortstring): integer;
+var
+  s2: shortstring;
+begin
+  s2 := s1;
+  result := length(s2);
+end;
+
+
+function calclength2(const s1: ansistring): integer;
+var
+  s2: ansistring;
+begin
+  s2 := s1;
+  result := length(s2);
+end;
+
+begin
+end.