gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: proctype and procedure type checking fully implemented


From: Fischlin Andreas
Subject: Re: proctype and procedure type checking fully implemented
Date: Sun, 21 Apr 2024 15:24:18 +0000

Dear Benjamin,

See below:

On 21 Apr 2024, at 16:29, Benjamin Kowarsch <trijezdci@gmail.com> wrote:



On Sun, 21 Apr 2024 at 22:09, Fischlin Andreas wrote:

WriteString ('the value is: ') ; WriteCard (func, 5) ; WriteLn

as most likely intended is first of all "syntactically wrong", as it should be written as

WriteString ('the value is: ') ; WriteCard (func(), 5) ; WriteLn

I wholeheartedly agree. 
 
Your example  WriteCard (func, 5) would then lead to following compile time error message

Procedure type of ‘func’ is not assignment compatible with the corresponding formal parameter of ‘WriteCard’

Agreed.
 

and a statement such as  WriteCard (func(), 5) should also lead to a compilation error message. Then the compiler error message could perhaps be similar to

Type returned by ‘func’ is not assignment compatible with the corresponding formal parameter of ‘WriteCard’

Agreed.
 
PROCEDURE func () : INTEGER ;
BEING
...
is accepted by the compiler with   WriteCard (func(), 5)  and leads at most to a runtime error, e.g. if func would return a negative value.

That might be the case in Pascal, and some versions of Oberon, but not in Modula-2 which follows name equivalence and does not use type promotion. Therefore it should cause a compile time error because the return type of function func is not compatible with the respective formal parameter of procedure WriteCard. The former is INTEGER, the latter CARDINAL.

Sorry, we are talking here only about assignment compatibility as the formal parameter of WriteCard is by value. In M2 assignments such as

x := y;

or

y := x;

with

VAR x: CARDINAL; y: INTEGER;

have always been legal. Not only in Pascal, but also in Modula-2. The only additional effort needed by a compiler is to generate code that checks for range errors at run time as INTEGER and CARDINAL typically overlap only by the upper (positive) half of INTEGER.

BTW, I took out my old Classic Mac and tested with MacMETH, one of the best PIM compilers, which was first largely written by Niklaus Wirth himself. Compile and run-time errors are encountered exactly for the cases as described in my previous e-mail.

I do not see that here would be any type promotion necessary. A statement such as  WriteCard (func(), 5) merely requires assignment compatibility as func is implicitly executed, and the result returned. The actual parameter for any by value formal parameter can be an _expression_. Thus a statement such as 

  WriteCard (func() + 1, 5)
is also fully legal M2. Otherwise a statement such as 

x := y + 5;

would also not be legal M2. Of course

x := x + y;

is illegal as a mixed type _expression_ results. But this does not exclude assignment compatibility between INTEGER and CARDINAL.

Right, Benjamin? ;-)

Andreas


regards
benjamin

Attachment: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]