Type Tests on Elements of Arrays

Report any suspected bugs that you find

Type Tests on Elements of Arrays

Postby cfbsoftware » Sat Apr 13, 2019 4:25 am

gray wrote:Here's a loosely related follow-up issue I ran into today:
Code: Select all
MODULE M1;

  TYPE
    T1 = POINTER TO T1Desc;
    T1Desc = RECORD
    END;

  VAR
    ta: ARRAY 4 OF T1;
    t: T1;
   
BEGIN
  CASE ta[0] OF (* 1: does not compile: invalid type *)
    T1:
  END;
 
  IF ta[0] IS T1 THEN END; (* 2: does not compile: compiler error; reg stack not empty *)
 
  t := ta[0];
  CASE t OF   (* 3: compiles *)
    T1:
  END

END M1.


I was baffled by these errors (cases 1 & 2), as the code seems innocuous and straightforward. Any advice here, apart from using workaround 3?
Last edited by cfbsoftware on Sat Apr 13, 2019 4:34 am, edited 1 time in total.
Reason: Message relocated from Astrobe for ARM Cortex-M3, M4 and M7 forum.
cfbsoftware
Site Admin
 
Posts: 383
Joined: Fri Dec 31, 2010 12:30 pm

Re: Type Tests on Elements of Arrays

Postby cfbsoftware » Sun Apr 14, 2019 11:09 am

Good questions!

It took some investigation and discussions with colleagues to satisfy myself that the CASE statements in your example are behaving as designed. The EBNF syntax for the CASE statement in the Oberon report, where the subject of a CASE statement is an expression, only applies to the numeric form of CASE statement. There is an alternative EBNF definition in ‘Programming in Oberon’ (Rev 5.10.2015) that defines the type test form of the CASE statement:

Code: Select all
CaseStatement = CASE qualident OF case {"|" case} END.
case = [qualident ":" StatementSequence].

A combination of both forms of CASE statement is actually implemented in the Cortex-M compilers.

The type test CASE is functionally consistent with Oberon-2's WITH statement (minus the ELSE) which it replaces. I'll add a section to the Oberon Guide to clarify this usage.

The IS test in your example compiles correctly when ta[0] is an element of a local array variable. The bug you reported occurs when ta[0] is an element of a global array variable. I hope to be able to fix this in the next maintenance release.
cfbsoftware
Site Admin
 
Posts: 383
Joined: Fri Dec 31, 2010 12:30 pm


Return to Bug Reports