MSIR.0789 Implied return not valid for methods that return a value: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Created page with "A code path analysis of a <tt>Function</tt> or property <tt>Get</tt> method has determined that it is possible to get to the end of the method without executing a <tt>return</tt>...")
 
m (1 revision)
(No difference)

Revision as of 16:45, 9 November 2010

A code path analysis of a Function or property Get method has determined that it is possible to get to the end of the method without executing a return statement and so have to do an implied return. But these methods require a return value and, of course, there can be no return value on an implied return. If it is felt that the compiler is in error and, in fact, an implied return should never be required, contact Sirius Software technical support with the contents of the method in question.

Note that the compiler can't make data-dependent decisions about what code might or might not be executed.

 For example, in<pre> function genderString is string len 16 if %sex eq 'M' then return 'male' elseif %sex eq 'F' then return 'female' end if end subroutine

one might "know" that %sex will always be either "M" or "F", but the compiler really has no way of knowing this.

 One can restructure the code to make this clear to the compiler and avoid the MSIR.0789 message:<pre> function genderString is string len 16 if %sex eq 'M' then return 'male' else return 'female' end if end subroutine
 Another way to restructure it to accomplish the same thing is:<pre> function genderString is string len 16 if %sex eq 'M' then return 'male' end if return 'female' end subroutine
 It might be a good idea to add an assertion that validates our assumption that %sex is always "M" or "F":<pre> function genderString is string len 16 if %sex eq 'M' then return 'male' end if assert %sex eq 'F' return 'female' end subroutine