MSIR.0789 Implied return not valid for methods that return a value

From m204wiki
Revision as of 18:44, 23 April 2014 by JALWiccan (talk | contribs) (Automatically generated page update)
Jump to navigation Jump to search

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 Technical Support 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 the following:

function genderString is string len 16 if %sex eq 'M' then return 'male' elseif %sex eq 'F' then return 'female' end if end subroutine

You might "know" that %sex will always be either "M" or "F", but the compiler really has no way of knowing this. You can restructure the code to make this clear to the compiler and avoid the MSIR.0789 message:

function genderString is string len 16 if %sex eq 'M' then return 'male' else return 'female' end if end subroutine

Another way to restructure to accomplish the same thing is:

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":

function genderString is string len 16 if %sex eq 'M' then return 'male' end if assert %sex eq 'F' return 'female' end subroutine