[Oberon] Dynamic type of record var parameter
August Karlstrom
fusionfile at gmail.com
Tue Jan 12 11:40:52 CET 2021
On 2021-01-11 23:44, chris wrote:
> 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?
Probably an error in the Project Oberon compiler. I just tried your
example with OBNC (replacing Texts with Out) and it (correctly?) prints
is r2
is r0
is r2
is r2
Here is a somewhat minimal example which highlights the issue:
MODULE Test2;
IMPORT Out;
TYPE
T0 = RECORD END;
T1 = RECORD (T0) END;
P0 = POINTER TO T0;
P1 = POINTER TO T1;
PROCEDURE PrintDynamicType(VAR x: T0);
BEGIN
CASE x OF
T1: Out.String("T1") |
T0: Out.String("T0")
END;
Out.Ln
END PrintDynamicType;
PROCEDURE Run*;
VAR p0: P0;
p1: P1;
BEGIN
NEW(p1);
p0 := p1;
PrintDynamicType(p0^)
END Run;
END Test2.
-- August
More information about the Oberon
mailing list