Re: [ooc-compiler] WITH statement and parametric types
Brought to you by:
mva
|
From: Michael v. A. <mic...@gm...> - 2005-10-07 16:49:55
|
Sorry, the recent 2.1.9 release does not run the test case below
correctly. I messed up my test suite _again_ by only running type
tests with simple type variables :-/
I'll try to find a solution over the weekend.
-- mva
On 26/06/05, vedmed <ve...@in...> wrote:
> I declare parametric type, and want to redefine procedure "Equals":
>
> MODULE Test;
>
> IMPORT Object, Out;
>
> TYPE
> Alp(T: Object.Object) =3D POINTER TO AlpDesc(T);
> AlpDesc(T: Object.Object) =3D RECORD(Object.ObjectDesc)
> val: LONGINT;
> END;
>
> Bet =3D POINTER TO BetDesc;
> BetDesc =3D RECORD(Object.ObjectDesc)
>
> END;
>
> Gam =3D Alp(Bet);
>
> VAR
> g1: Gam;
> g2: Gam;
>
> PROCEDURE (a: Alp(T)) INIT*(val: INTEGER);
> BEGIN
> a.val :=3D val;
> END INIT;
>
> PROCEDURE (x: Alp(T)) Equals*(y: Object.Object): BOOLEAN;
> BEGIN
> IF y =3D NIL THEN
> RETURN FALSE;
> ELSE
> WITH y: Alp(T) DO
> RETURN x.val =3D y.val;
> ELSE
> RETURN FALSE;
> END;
> END;
> END Equals;
>
> BEGIN
> g1 :=3D NEW(Gam, 1);
> g2 :=3D NEW(Gam, 1);
> IF g1.Equals(g2) THEN
> Out.String('equals'); Out.Ln();
> ELSE
> Out.String('not equals'); Out.Ln();
> END;
> END Test.
>
> But in this example "Equal" always return FALSE, because of WITH
> statement can not recognize parameter "y" as value of type "Alp" or
> "Gam". Expressions "WITH y: Alp DO" and "WITH y: Alp(Object.Object) DO"
> also not works. So I can't see a way how to get access to field "val" of
> parameter "y". I don't know it is bug of compiler or some logic problem.
> I suppose that full check of type and all of him parameters is difficult
> task for compiler and can slow down compiled programs, but I assume,
> that in most cases will be enough only checks of base type.
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclic=
k
> _______________________________________________
> ooc-compiler mailing list
> ooc...@li...
> https://lists.sourceforge.net/lists/listinfo/ooc-compiler
>
|