From 86bf41f68960c86bf0ab1874a57f7b3d46a6c7ed Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 6 Jul 2005 13:09:50 +0000 Subject: [PATCH] * prefer shortstring to ansistring over ansistring to shortstring * don't prefer widestring to short/ansistring git-svn-id: trunk@594 - --- .gitattributes | 1 + compiler/defcmp.pas | 21 ++++++++++++++++----- tests/webtbs/tw4162.pp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tests/webtbs/tw4162.pp diff --git a/.gitattributes b/.gitattributes index 7bb8ab4630..59e60bd70a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6134,6 +6134,7 @@ tests/webtbs/tw4140.pp svneol=native#text/plain tests/webtbs/tw4150.pp svneol=native#text/plain tests/webtbs/tw4151.pp svneol=native#text/plain tests/webtbs/tw4152.pp svneol=native#text/plain +tests/webtbs/tw4162.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 diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas index 558ff15aab..b99945fc5b 100644 --- a/compiler/defcmp.pas +++ b/compiler/defcmp.pas @@ -304,12 +304,23 @@ implementation else begin doconv:=tc_string_2_string; - { 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_l2 + 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 - eq:=te_convert_l3; + { 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; end; end; orddef : diff --git a/tests/webtbs/tw4162.pp b/tests/webtbs/tw4162.pp new file mode 100644 index 0000000000..8eddcc8b31 --- /dev/null +++ b/tests/webtbs/tw4162.pp @@ -0,0 +1,12 @@ + +Var + S: ansistring; + SS: shortstring; +Begin + SS := 'find'; + SetLength(S, 300); + S := S + SS; + Writeln(Pos(SS, S)); // This will not find the occurance of 'find' + if pos(ss,s)<>301 then + halt(1); +End.