[Oberon] Serious type loophole in type case statements and a possible fix

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Sat Oct 31 16:32:37 CET 2020


I thank “the community” for the emails on this topic. I have condensed the feedback
to the new tentative definition of the type case statement below, and implemented it.

Of course, this is not a clean definition of this language construct anymore, but at
least it’s one with no more type loopholes in it. The only remaining question is, in
my view, just how much faster a “typical” program is by using *this* implementation.
If the answer is “not much faster”, I’m in favour of eliminating the type case statement

Anyone volunteering to do some benchmarking? The link to the implementation is below.

   * New (tentative) definition of the type case statement
   *
   *    CASE x OF
   *       T1: S1
   *     | T2: S2
   *    ELSE S3
   *    END
   *
   * It is modified such that it implements the following rules and restrictions:
   *
   *  - Case variables must be simple identifiers that cannot be followed by selectors, i.e. they cannot
   *    be elements of a structure (such as array elements or record fields).
   *  - If the type of the case variable is a record type, the case variable must be a variable
   *    parameter of the procedure containing the type case statement.
   *  - If the type of the case variable is a pointer type, the case variable must be either a local
   *    variable or a value parameter passed to the procedure containing the type case statement,
   *    and the case variable cannot itself be passed as a variable parameter to another procedure.
   *  - Assignments to case variables within the body of a type case statement are not allowed
   *    (however, assignments to individual fields of case variables are allowed).
   *
   * Such a type case statement disallows...
   *
   *   1. Case variables that are elements of a structure
   *   2. Global case variables
   *   3. Local case variables of a record type
   *   4. Case variables that are variable parameters of a pointer type
   *   5. Passing a case variable of a pointer type as a variable parameter to another procedure
   *   6. Assignments to case variables within the body of the type case statement
   *
   * but allows...
   *
   *   1. Local pointer variables as the case variable
   *   2. Value parameters of a pointer type as the case variable
   *   3. Variable parameters of a record type as the case variable
   *   4. Assignments to individual fields x.f of a case variable x
   *   5. Passing a case variable of a pointer type as a *value* parameter to another procedure
   *   6. Passing a case variable of a record type as a *value* parameter to another procedure
   *   6. Passing a case variable of a record type as a *variable* parameter to another procedure
 
Implementation and documentation (the first link is an implementation for Project Oberon 2013):

http://github.com/andreaspirklbauer/Oberon-type-case-statement-without-loopholes

http://github.com/andreaspirklbauer/Oberon-extended/blob/master/Documentation/The-Revised-Oberon2-Programming-Language.pdf






More information about the Oberon mailing list