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: Benjamin Kowarsch
Subject: Re: proctype and procedure type checking fully implemented
Date: Sun, 21 Apr 2024 23:29:09 +0900



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.

regards
benjamin

reply via email to

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