[Oberon] Case statements containing base type labels
chris
chris at gcjd.org
Mon Aug 28 20:51:20 CEST 2023
On Mon, 28 Aug 2023 19:27:44 +0200, August Karlstrom wrote:
> My current conclusion is that a case statement where one type label
> is an extension of another is not well-defined.
I agree. IMHO it was a bad idea to mix the WITH statement and the CASE
statement at all.
The WITH statement was defined by IF/ELSIF so no problem here:
For example in "Object-Oriented Programming in Oberon-2" (Mössenböck
1993) Appendix A:
"WITH v: T1 DO S1 | v: T2 DO S2 ELSE S3 END
has the following meaning: if the dynamic type of v is T1, then the
statement sequence S1 is executed, where v is regarded as if it had the
static type T1; else if the dynamic type of v is T2, then S2 is
executed, where v is regarded as if it had the static type T2; else S3
is executed. T1 and T2 must be extensions of T0."
As explained by Wirth in "Differences between Revised Oberon and
Oberon" (Wirth 2011)
"The case statement performs the same function as the if statement.
However, it is intended to use a different technique of implementation,
namely a single, indexed branch instead of a cascade of conditional
branches."
The 2011 version of Oberon-07 only allows INTEGER and CHAR for CASE
statements.
Mixing with type tests makes no sense as they will most likely be
implemented as several IF - ELSIF statements.
> I think an ambitious
> compiler could even reject such a statement, similar to how repeated
> case labels can be handled.
I think it should reject such code as the case labels are not distinct
from each other. Otherwise the semantics of the CASE statement would
change for this case from the original intention and the other variant
with INTEGER/CHAR labels which must be distinct.
Greetings, chris
More information about the Oberon
mailing list