Bug with invalid pointers
johnperry-math opened this issue · comments
There seems to be a bug in internalNameAt
that manifests with this code:
MODULE TestPt;
TYPE
PT = POINTER TO ARRAY 5 OF BOOLEAN;
VAR
pt: PT;
BEGIN
pt := NIL;
END TestPt.
The output I get is
$ java -cp $OBERON_BIN oberonc build TestPt.obn
TestPt.obn:5:37: must point to record
Exception in thread "main" java.lang.NullPointerException
at OJG.internalNameAt(OJG.Mod:139)
at OJG.DescriptorR(OJG.Mod:171)
at OJG.DescriptorAt(OJG.Mod:209)
at OJG.Descriptor(OJG.Mod:214)
at OJG.Header(OJG.Mod:2310)
at OJP.Module(OJP.Mod:1378)
at OJP.Compile(OJP.Mod:1410)
at oberonc.Main(oberonc.Mod:40)
at oberonc.main(oberonc.Mod)
It looks as if it's because type.base.typobj
is NIL
. If I change it as follows:
IF type.base.typobj # NIL THEN
i := Strings.Write(type.base.typobj.name, out, i)
ELSE
i := Strings.Write(type.typobj.name, out, i)
END
...then the compiler doesn't crash. Though maybe it doesn't need the ELSE
case anyway; could it be left blank?
Thanks for reporting this bug.
I have pushed a fix for this, together with another unrelated fix.
Like in other parts of the compiler, when we have a type error, we report it and set the type to a dummy INTEGER
so that we resume in stable state.
Thanks; I merged it to my fork.
Here's a related issue that might not actually be a bug. In the code below, A
is never defined, but I can assign NIL
to a pointer to A
. My impression from reading 6.4 of The Programming Language Oberon is that A
should be defined, but perhaps not?
MODULE TestPtr;
TYPE
PT = POINTER TO A; (* A is undefined *)
VAR
pt: PT;
BEGIN (* A is still undefined *)
pt := NIL;
END TestPtr.
Please try out the new fix in master. Thanks!
It works!