From 260861e1841572f9e58edb10618856f15f26da9c Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 19 Oct 2005 06:38:29 +0000 Subject: [PATCH] * calculate distance between related objectdefs git-svn-id: trunk@1492 - --- .gitattributes | 1 + compiler/htypechk.pas | 19 +++++++++++++++++++ tests/webtbs/tw4278.pp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100755 tests/webtbs/tw4278.pp diff --git a/.gitattributes b/.gitattributes index b34d70fad6..c86e3dd3ea 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6320,6 +6320,7 @@ tests/webtbs/tw4260.pp svneol=native#text/plain tests/webtbs/tw4266.pp -text tests/webtbs/tw4272.pp svneol=native#text/plain tests/webtbs/tw4277.pp svneol=native#text/plain +tests/webtbs/tw4278.pp svneol=native#text/plain tests/webtbs/tw4290.pp svneol=native#text/plain tests/webtbs/tw4294.pp svneol=native#text/plain tests/webtbs/tw4308.pp svneol=native#text/plain diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index c82ec9b9e1..f21ffd69da 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -1737,6 +1737,7 @@ implementation paraidx : integer; currparanr : byte; rfh,rth : bestreal; + objdef : tobjectdef; def_from, def_to : tdef; currpt, @@ -1862,6 +1863,24 @@ implementation hp^.ordinal_distance:=hp^.ordinal_distance+rfh; end else + { related object parameters also need to determine the distance between the current + object and the object we are comparing with } + if (def_from.deftype=objectdef) and + (def_to.deftype=objectdef) and + (tobjectdef(def_from).objecttype=tobjectdef(def_to).objecttype) and + tobjectdef(def_from).is_related(tobjectdef(def_to)) then + begin + eq:=te_convert_l1; + objdef:=tobjectdef(def_from); + while assigned(objdef) do + begin + if objdef=def_to then + break; + hp^.ordinal_distance:=hp^.ordinal_distance+1; + objdef:=objdef.childof; + end; + end + else { generic type comparision } begin eq:=compare_defs_ext(def_from,def_to,currpt.left.nodetype,convtype,pdoper,cdoptions); diff --git a/tests/webtbs/tw4278.pp b/tests/webtbs/tw4278.pp new file mode 100755 index 0000000000..335a6a6b1c --- /dev/null +++ b/tests/webtbs/tw4278.pp @@ -0,0 +1,32 @@ +{$mode objfpc} + +var + err : boolean; + +type + TA = class + end; + TB = class(TA) + end; + TC = class(TB) + end; + +procedure Test(const A: TA); overload; +begin +end; + +procedure Test(const B: TB); overload; +begin + writeln('ok'); + err:=false; +end; + +var + X : TC; + +begin + err:=true; + Test(X); + if err then + halt(1); +end.