MODULE TVariant; (* Variant records: plain fields pack before the CASE tag; every branch's fields overlay in one region after the tag. Exit 31. *) VAR ExitCode : INTEGER; TYPE Kind = (circle, square, rect); Shape = RECORD id : INTEGER; CASE k : Kind OF circle : radius : INTEGER; | square : side : INTEGER; | rect : w, h : INTEGER; END; END; VAR s : Shape; BEGIN ExitCode := 0; s.id := 7; s.k := rect; s.w := 3; s.h := 4; IF s.id = 7 THEN ExitCode := ExitCode + 1 ELSE ExitCode := 100 END; IF s.k = rect THEN ExitCode := ExitCode + 2 ELSE ExitCode := 101 END; IF s.h = 4 THEN ExitCode := ExitCode + 4 ELSE ExitCode := 102 END; (* w and h share storage: the last store wins *) s.w := 9; IF s.h = 9 THEN ExitCode := ExitCode + 8 ELSE ExitCode := 103 END; (* switching branch reuses the same slot *) s.k := square; s.side := 5; IF s.side = 5 THEN ExitCode := ExitCode + 16 ELSE ExitCode := 104 END END TVariant.