Page 1 of 1

Type Tests

Posted: Sat Jul 19, 2025 11:38 am
by gray
Consider this first test case:

Code: Select all

MODULE M0;

  IMPORT Main, Out;

  TYPE
    Mp* = POINTER TO Mdesc;
    M0p* = POINTER TO M0desc;
    Mdesc* = RECORD END;
    M0desc* = RECORD (Mdesc) END;
    
    M1p* = POINTER TO M1desc;
    M1desc* = RECORD (M0desc) END;

  VAR
    mp: Mp;
    m0p: M0p;
    m1p: M1p;

BEGIN
  NEW(m1p);
  mp := m1p;
  ASSERT(mp IS M0p, 200);
  Out.String("assert ok"); Out.Ln;
  m0p := mp(M0p);
  Out.String("type guard ok"); Out.Ln
END M0.
As expected, the program runs with both the ASSERT as well as the type guard passing.

Now consider this modified second test case, moving part of the type defs to another module:

Code: Select all

MODULE T2;
  TYPE
    Mp* = POINTER TO Mdesc;
    M0p* = POINTER TO M0desc;
    Mdesc* = RECORD END;
    M0desc* = RECORD (Mdesc) END;
END T2.

MODULE M1;

  IMPORT T2, Main, Out;

  TYPE
    M1p* = POINTER TO M1desc;
    M1desc* = RECORD (T2.M0desc) END;

  VAR
    mp: T2.Mp;
    m0p: T2.M0p;
    m1p: M1p;

BEGIN
  NEW(m1p);
  mp := m1p;
  ASSERT(mp IS T2.M0p, 200);
  Out.String("assert ok"); Out.Ln;
  m0p := mp(T2.M0p);
  Out.String("type guard ok"); Out.Ln
END M1.
Now the ASSERT fails, and when commenting the ASSERT out, so does the type guard.

What do I miss?

(Latest Astrobe for RP2350, command line compiler and linker.)