Browse Source

* Fixed passing of open array of wide string literals to function which expects 'array of pwidechar' parameter in case source file has utf8 encoding. Compiler thrown the following error in such case: Incompatible type for arg no. 1: Got "Array Of Const/Constant Open Array of WideString", expected "Open Array Of PWideChar".
+ Test for this issue.

git-svn-id: trunk@11581 -

yury 17 years ago
parent
commit
8818df640f
3 changed files with 24 additions and 6 deletions
  1. 1 0
      .gitattributes
  2. 2 6
      compiler/defcmp.pas
  3. 21 0
      tests/tbs/tb0555.pp

+ 1 - 0
.gitattributes

@@ -7137,6 +7137,7 @@ tests/tbs/tb0551.pp svneol=native#text/plain
 tests/tbs/tb0552.pp svneol=native#text/plain
 tests/tbs/tb0553.pp svneol=native#text/plain
 tests/tbs/tb0554.pp svneol=native#text/plain
+tests/tbs/tb0555.pp svneol=native#text/plain
 tests/tbs/tb205.pp svneol=native#text/plain
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain

+ 2 - 6
compiler/defcmp.pas

@@ -890,18 +890,14 @@ implementation
                    begin
                      { string constant (which can be part of array constructor)
                        to zero terminated string constant }
-                     if (((fromtreetype = arrayconstructorn) and
-                          { can't use is_chararray, because returns false for }
-                          { array constructors                                }
-                          is_char(tarraydef(def_from).elementdef)) or
-                         (fromtreetype = stringconstn)) and
+                     if (fromtreetype = stringconstn) and
                         (is_pchar(def_to) or is_pwidechar(def_to)) then
                       begin
                         doconv:=tc_cstring_2_pchar;
                         eq:=te_convert_l2;
                       end
                      else
-                      if cdo_explicit in cdoptions then
+                      if (cdo_explicit in cdoptions) or (fromtreetype = arrayconstructorn) then
                        begin
                          { pchar(ansistring) }
                          if is_pchar(def_to) and

+ 21 - 0
tests/tbs/tb0555.pp

@@ -0,0 +1,21 @@
+
+function DoTest(params: array of PWideChar): WideString;
+var
+  i: integer;
+  res: WideString;
+begin
+  res:='';
+  for i:=Low(params) to High(params) do
+    res:=res + params[i];
+  DoTest:=res;
+end;
+
+var
+  s: WideString;
+begin
+  s:=DoTest(['аб', 'вг', 'де']);
+  if s <> 'абвгде' then begin
+    writeln('Test failed. S=', s);
+    Halt(1);
+  end;
+end.