ソースを参照

* overload choosing for ansistring -> short/wide

git-svn-id: trunk@983 -
peter 20 年 前
コミット
f4c15f16bf
3 ファイル変更46 行追加17 行削除
  1. 1 0
      .gitattributes
  2. 29 17
      compiler/defcmp.pas
  3. 16 0
      tests/webtbs/tw4272.pp

+ 1 - 0
.gitattributes

@@ -6186,6 +6186,7 @@ tests/webtbs/tw4240.pp svneol=native#text/plain
 tests/webtbs/tw4247.pp svneol=native#text/plain
 tests/webtbs/tw4253.pp svneol=native#text/plain
 tests/webtbs/tw4260.pp svneol=native#text/plain
+tests/webtbs/tw4272.pp svneol=native#text/plain
 tests/webtbs/tw4277.pp svneol=native#text/plain
 tests/webtbs/tw4294.pp svneol=native#text/plain
 tests/webtbs/tw4308.pp svneol=native#text/plain

+ 29 - 17
compiler/defcmp.pas

@@ -304,23 +304,35 @@ implementation
                      else
                        begin
                          doconv:=tc_string_2_string;
-                         if tstringdef(def_from).string_typ=st_widestring then
-                           begin
-                             { Prefer conversions to shortstring over other
-                               conversions. This is compatible with Delphi (PFV) }
-                             if tstringdef(def_to).string_typ=st_shortstring then
-                               eq:=te_convert_l3
-                             else
-                               eq:=te_convert_l2;
-                           end
-                         else
-                           { Prefer shortstrings of different length or conversions
-                             from shortstring to ansistring }
-                           if (tstringdef(def_from).string_typ=st_shortstring) and
-                              (tstringdef(def_to).string_typ in [st_shortstring,st_ansistring]) then
-                           eq:=te_convert_l1
-                         else
-                           eq:=te_convert_l2;
+                         case tstringdef(def_from).string_typ of
+                           st_widestring :
+                             begin
+                               { Prefer conversions to ansistring }
+                               if tstringdef(def_to).string_typ=st_ansistring then
+                                 eq:=te_convert_l2
+                               else
+                                 eq:=te_convert_l3;
+                             end;
+                           st_shortstring :
+                             begin
+                               { Prefer shortstrings of different length or conversions
+                                 from shortstring to ansistring }
+                               if (tstringdef(def_to).string_typ=st_shortstring) then
+                                 eq:=te_convert_l1
+                               else if tstringdef(def_to).string_typ=st_ansistring then
+                                 eq:=te_convert_l2
+                               else
+                                 eq:=te_convert_l3;
+                             end;
+                           st_ansistring :
+                             begin
+                               { Prefer conversion to widestrings }
+                               if (tstringdef(def_to).string_typ=st_widestring) then
+                                 eq:=te_convert_l2
+                               else
+                                 eq:=te_convert_l3;
+                             end;
+                         end;
                        end;
                    end;
                  orddef :

+ 16 - 0
tests/webtbs/tw4272.pp

@@ -0,0 +1,16 @@
+procedure go(const w: widestring);overload;
+begin
+writeln('wide: ',w);
+end;
+
+procedure go(const w: shortstring);overload;
+begin
+writeln('short: ',w);
+end;
+
+var
+  s: ansistring;
+begin
+  s:='test';
+  go(s); //-->compiler can not determine whitch overloaded function to call
+end.