Type Tests

General discussions about working with the Astrobe IDE and programming the Raspberry Pi RP2040 and the Pi Pico board.
Post Reply
gray
Posts: 172
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

Type Tests

Post by gray » Sat Jul 19, 2025 11:38 am

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.)

Post Reply