On Sun, Nov 30, 2003 at 06:46:06PM +0100, Waldek Hebisch wrote:
AFAIKS GPC implements resticted types quite unlike what EP requires.
- Restriced types should be different then underlying type (6.4.1 says
that restricted-type is a new-type, and new-type is different from other types. So according to rules for return values the following program (accepted by GPC in EP mode) is incorrect:
program prog; type a=0..5; b= restricted a; var c:a; procedure foo(function bar:b); begin end; function baz:a; begin baz := c end; begin foo(baz) end .
I agree.
- According to 6.9.2.2 assignment to variable of restricted type is
legal, and IMHO the following program (rejected by GPC) is legal:
program prog; type a=0..5; b= restricted a; var c:b; begin c := 0; end .
My understanding of 6.9.2.2 is that either the value of the RHS should be assignment-compatible with the type of the LHS (which is not the case here), or with its underlying type, _provided the LHS is a function result variable_. Thus your example is IMHO illegal, whereas the program below is legal (and accepted by GPC):
program prog;
type a=0..5; b= restricted a;
function c:b; begin c := 0; end;
var d: b;
begin d := c end.
Emil