Преглед на файлове

* fix passing string to open array of string

git-svn-id: trunk@8137 -
peter преди 18 години
родител
ревизия
98cc116dd2
променени са 3 файла, в които са добавени 46 реда и са изтрити 17 реда
  1. 1 0
      .gitattributes
  2. 21 17
      compiler/ncal.pas
  3. 24 0
      tests/webtbs/tw9309.pp

+ 1 - 0
.gitattributes

@@ -8353,6 +8353,7 @@ tests/webtbs/tw9209.pp svneol=native#text/plain
 tests/webtbs/tw9221.pp svneol=native#text/plain
 tests/webtbs/tw9261.pp svneol=native#text/x-pascal
 tests/webtbs/tw9278.pp svneol=native#text/plain
+tests/webtbs/tw9309.pp -text
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 21 - 17
compiler/ncal.pas

@@ -591,7 +591,8 @@ implementation
               if (paradef.typ<>arraydef) then
                 internalerror(200405241);
               { passing a string to an array of char }
-              if (p.nodetype=stringconstn) then
+              if (p.nodetype=stringconstn) and
+                 is_char(tarraydef(paradef).elementdef) then
                 begin
                   len:=tstringconstnode(p).len;
                   if len>0 then
@@ -679,22 +680,25 @@ implementation
                  hightree := geninlinenode(in_high_x,false,p.getcopy);
                end
               else
-               begin
-                 { passing a string to an array of char }
-                 if (p.nodetype=stringconstn) then
-                   begin
-                     len:=tstringconstnode(p).len;
-                     if len>0 then
-                      dec(len);
-                   end
-                 else
-                   begin
-                     maybe_load_para_in_temp(p);
-                     hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
-                                               cordconstnode.create(1,sinttype,false));
-                     loadconst:=false;
-                   end;
-               end;
+               { handle special case of passing an single string to an array of string }
+               if compare_defs(tarraydef(paradef).elementdef,p.resultdef,nothingn)>=te_equal then
+                len:=0
+              else
+               { passing a string to an array of char }
+               if (p.nodetype=stringconstn) and
+                  is_char(tarraydef(paradef).elementdef) then
+                 begin
+                   len:=tstringconstnode(p).len;
+                   if len>0 then
+                    dec(len);
+                 end
+              else
+                begin
+                  maybe_load_para_in_temp(p);
+                  hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
+                                            cordconstnode.create(1,sinttype,false));
+                  loadconst:=false;
+                end;
            end;
         else
           len:=0;

+ 24 - 0
tests/webtbs/tw9309.pp

@@ -0,0 +1,24 @@
+program openarrayhigh;
+{$ifdef FPC}{$mode objfpc}{$h+}{$INTERFACES CORBA}{$endif}
+{$ifdef mswindows}{$apptype console}{$endif}
+uses
+ {$ifdef FPC}{$ifdef linux}cthreads,{$endif}{$endif}
+ sysutils;
+
+procedure testproc(const par1: array of string);
+var
+ str1: ansistring;
+begin
+ writeln(high(par1));
+ flush(output);
+ str1:= par1[high(par1)];
+ writeln(str1);
+ flush(output);
+end;
+
+var
+ str1: ansistring;
+begin
+ str1:= 'abcdefg';
+ testproc(str1);
+end.