diff --git a/.gitattributes b/.gitattributes index 6bd8dcaae2..5405511ce0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8135,6 +8135,7 @@ tests/webtbs/tw1104.pp svneol=native#text/plain tests/webtbs/tw11042.pp svneol=native#text/plain tests/webtbs/tw11053.pp svneol=native#text/plain tests/webtbs/tw1111.pp svneol=native#text/plain +tests/webtbs/tw11139.pp svneol=native#text/plain tests/webtbs/tw1117.pp svneol=native#text/plain tests/webtbs/tw1122.pp svneol=native#text/plain tests/webtbs/tw1123.pp svneol=native#text/plain diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index 0df200c3ba..780b3a09c2 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -2364,8 +2364,20 @@ implementation ord(currvcl in conflictvcls)-ord(bestvcl in conflictvcls); end; + + function getfirstrealparaidx(pd: pcandidate): integer; + begin + { can be different for currpd and bestpd in case of overloaded } + { functions, e.g. lowercase():char and lowercase():shortstring } + { (depending on the calling convention and parameter order) } + result:=pd^.firstparaidx; + while (result>=0) and (vo_is_hidden_para in tparavarsym(pd^.data.paras[result]).varoptions) do + dec(result); + if (vo_is_hidden_para in tparavarsym(pd^.data.paras[result]).varoptions) then + internalerror(2006122803); + end; + var - paraidx : integer; currpara, bestpara: tparavarsym; currvcl, bestvcl: tvariantequaltype; begin @@ -2375,18 +2387,8 @@ implementation < 0 when bestpd is better than currpd = 0 when both are equal } - if (currpd^.firstparaidx<>bestpd^.firstparaidx) then - internalerror(2006122801); - paraidx:=currpd^.firstparaidx; - while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(currpd^.data.paras[paraidx]).varoptions) do - if (vo_is_hidden_para in tparavarsym(bestpd^.data.paras[paraidx]).varoptions) then - dec(paraidx) - else - internalerror(2006122802); - if (vo_is_hidden_para in tparavarsym(currpd^.data.paras[paraidx]).varoptions) then - internalerror(2006122803); - currpara:=tparavarsym(currpd^.data.paras[paraidx]); - bestpara:=tparavarsym(bestpd^.data.paras[paraidx]); + currpara:=tparavarsym(currpd^.data.paras[getfirstrealparaidx(currpd)]); + bestpara:=tparavarsym(bestpd^.data.paras[getfirstrealparaidx(bestpd)]); { if one of the parameters is a regular variant, fall back to the } { default algorithm } diff --git a/tests/webtbs/tw11139.pp b/tests/webtbs/tw11139.pp new file mode 100644 index 0000000000..903ee5e7f3 --- /dev/null +++ b/tests/webtbs/tw11139.pp @@ -0,0 +1,28 @@ +function f(c: char): char; overload; +begin + halt(1); +end; + +function f(const s: shortstring): shortstring; overload; +begin + f:=lowercase(s); +end; + +function f(const a: ansistring): ansistring; overload; +begin + halt(3); +end; + +Procedure DoIt; +var avar:variant; + txt:String; +Begin +avar:='Hello'; +txt:=f(avar);//this line causes the compilation error +if (txt<>'hello') then + halt(4); +end; + +begin + doit; +end.