[Oberon] Dynamic type of record var parameter
Diego Sardina
dsar at eml.cc
Tue Jan 12 00:22:38 CET 2021
Yes, the last should be r2
--
Diego Sardina
On Mon, Jan 11, 2021, at 11:44 PM, chris wrote:
> Hello,
>
> please consider the following test of dynamic type of record variable
> parameters:
>
> MODULE Test;
>
> IMPORT Texts, Oberon;
>
> TYPE
> r0 = RECORD i : INTEGER; END;
> r1 = RECORD (r0) x : REAL END;
> r2 = RECORD (r1) c : CHAR END;
> p0 = POINTER TO r0;
> p1 = POINTER TO r1;
> p2 = POINTER TO r2;
>
> VAR W : Texts.Writer;
>
> PROCEDURE check(VAR r : r0);
> BEGIN
> IF r IS r2 THEN Texts.WriteString(W, "is r2") ELSIF r IS r1 THEN
> Texts.WriteString(W, "is r1")
> ELSIF r IS r0 THEN Texts.WriteString(W, "is r0") END;
> Texts.WriteLn(W)
> END eins;
>
> PROCEDURE do* ();
> VAR p : p0; r : r0; q : p2; t : r2;
> BEGIN
> NEW(p); NEW(q);
> check(t);
> check(p^);
> check(q^);
> p := q; check(p^);
> Texts.Append(Oberon.Log, W.buf);
> END do;
>
> BEGIN
> Texts.OpenWriter(W);
> END Test.
>
> Output from Oberon 2013 emulator is:
> is r2
> is r0
> is r2
> is r0
>
> What surprises me is the last one. The dynamic type is r2 not r0. It
> looks like the compiler uses the static type from the local variable p
> instead of the dynamic type of p^. Is this intended behavior?
>
> Greetings, chris
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
More information about the Oberon
mailing list