Project

General

Profile

Feature #95

Error/warning if fn-proc is neither fn nor proc?

Added by John Abbott about 12 years ago. Updated almost 8 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Parser/Interpreter
Target version:
Start date:
29 Feb 2012
Due date:
% Done:

0%

Estimated time:
Spent time:

Description

My email records show that we wrote about this on 2010-05-19.

C5 distinguishes fns from procs simply by the nature of the return statements appearing the definition. An parse-time error is signalled if there are two return statements of differing type.

At the moment no parse-time error (or warning) is given if a fn could "fall off the end" (but a run-time error is generated should execution actually fall off the end). We opted not to give any warning or error as it is difficult to do correct code analysis to determine when the source code is plausible, and the alternative is to force the user to insert annoying, needless return statements just to keep the parser quiet.

I now favour issuing a warning (at least), because a student supplied me with some code which did indeed have a missing final return. If I recall well, we have several levels of warnings, so maybe this warning could be (initially) issued only at the highest level (to avoid annoying too many people).


Related issues

Related to CoCoA-5 - Feature #492: New C5 fn for adjusting the warning levelNew2014-03-24

History

#1 Updated by Anna Maria Bigatti almost 12 years ago

  • Category set to Parser/Interpreter

#2 Updated by Anna Maria Bigatti almost 10 years ago

  • Target version set to CoCoA-5.1.0 Easter14

#3 Updated by John Abbott almost 10 years ago

  • Target version changed from CoCoA-5.1.0 Easter14 to CoCoA-5.?.?

#4 Updated by John Abbott almost 8 years ago

Here is a simple test case:

define f(x)
  if x > 0 then return 1; endif;
enddefine; -- f

Here is another test case:

define f(x)
  n := 0;
  while true do
    incr(ref n);
    if n > x then return n; endif;
  endwhile
enddefine

Also available in: Atom PDF