[Oberon] Dynamic type of record var parameter

chris chris at gcjd.org
Mon Jan 11 23:44:19 CET 2021


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


More information about the Oberon mailing list