* accept overloaded operators that return any shortstring type when needing

a conversion to a shortstring type (so an operator := that returns a
    string[255] can be used to assign this type to a string[80]) (mantis
    )
  * do not allow overloading := with a string[x<>255] as result type,
    because we want one such overload to satisfy all conversions (see
    previous point)

git-svn-id: trunk@12590 -
This commit is contained in:
Jonas Maebe 2009-01-24 15:12:19 +00:00
parent 5b4057db61
commit 2929624ffc
5 changed files with 46 additions and 2 deletions

2
.gitattributes vendored
View File

@ -8233,6 +8233,7 @@ tests/webtbf/tw11849a.pp svneol=native#text/plain
tests/webtbf/tw11862a.pp svneol=native#text/plain
tests/webtbf/tw11970.pp svneol=native#text/plain
tests/webtbf/tw12075.pp svneol=native#text/plain
tests/webtbf/tw12109a.pp svneol=native#text/plain
tests/webtbf/tw12303.pp svneol=native#text/plain
tests/webtbf/tw12329.pp svneol=native#text/plain
tests/webtbf/tw12365a.cfg svneol=native#text/plain
@ -8701,6 +8702,7 @@ tests/webtbs/tw12050b.pp svneol=native#text/plain
tests/webtbs/tw12051.pp svneol=native#text/plain
tests/webtbs/tw1207.pp svneol=native#text/plain
tests/webtbs/tw12076.pp svneol=native#text/plain
tests/webtbs/tw12109.pp svneol=native#text/plain
tests/webtbs/tw12151.pp svneol=native#text/plain
tests/webtbs/tw12186.pp svneol=native#text/plain
tests/webtbs/tw12202.pp svneol=native#text/plain

View File

@ -409,7 +409,16 @@ implementation
if optoken=_ASSIGNMENT then
begin
eq:=compare_defs_ext(ld,pf.returndef,nothingn,conv,pd,[cdo_explicit]);
result:=(eq=te_incompatible);
result:=
(eq=te_incompatible) and
{ don't allow overloading assigning to custom shortstring
types, because we also don't want to differentiate based
on different shortstring types (e.g.,
"operator :=(const v: variant) res: shorstring" also
has to work for assigning a variant to a string[80])
}
(not is_shortstring(pf.returndef) or
(tstringdef(pf.returndef).len=255));
end
else
begin

View File

@ -702,7 +702,9 @@ implementation
for i:=0 to ProcdefList.Count-1 do
begin
pd:=tprocdef(ProcdefList[i]);
if equal_defs(todef,pd.returndef) and
if (equal_defs(todef,pd.returndef) or
{ shortstrings of different lengths are ok as result }
(is_shortstring(todef) and is_shortstring(pd.returndef))) and
{ the result type must be always really equal and not an alias,
if you mess with this code, check tw4093 }
((todef=pd.returndef) or

12
tests/webtbf/tw12109a.pp Normal file
View File

@ -0,0 +1,12 @@
{ %fail }
type
tr = record end;
ts2 = string[80];
operator :=(const r: tr) res: ts2;
begin
end;
begin
end.

19
tests/webtbs/tw12109.pp Normal file
View File

@ -0,0 +1,19 @@
{$mode delphi}
Procedure test;
Var
V : Variant;
SS : String [80];
Begin
V := 'Hello';
SS := V;
if (ss<>'Hello') then
halt(1);
End;
begin
test;
end.