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