MSIR.0789 Implied return not valid for methods that return a value: Difference between revisions
(Automatically generated page update) |
(Automatically generated page update) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
A code path analysis of a < | A code path analysis of a <var>Function</var> or property <var>Get</var> method has determined that it is possible to get to the end of the method without executing a <var>Return</var> statement and so have to do an implied return. But these methods require a return value, and 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 [[Contacting Rocket Software 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: | |||
<p class="code">function genderString is string len 16 | |||
if %sex eq 'M' then | |||
return 'male' | |||
elseif %sex eq 'F' then return 'female' | |||
end if | |||
end subroutine</p> | |||
You might "know" that <code>%sex</code> 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: | |||
<p class="code">function genderString is string len 16 | |||
if %sex eq 'M' then | |||
return 'male' | |||
else return 'female' | |||
end if | |||
end subroutine</p> | |||
[[Category: | Another way to restructure to accomplish the same thing is: | ||
<p class="code">function genderString is string len 16 | |||
if %sex eq 'M' then | |||
return 'male' | |||
end if | |||
return 'female' | |||
end subroutine</p> | |||
It might be a good idea to add an assertion that validates our assumption that <code>%sex</code> is always "M" or "F": | |||
<p class="code">function genderString is string len 16 | |||
if %sex eq 'M' then | |||
return 'male' | |||
end if | |||
assert %sex eq 'F' | |||
return 'female' | |||
end subroutine</p> | |||
{{Template:MSIR.0789 footer}} | |||
[[Category:MSIR.0600 - MSIR.0799]] |
Latest revision as of 23:34, 3 March 2017
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 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 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
Message attributes:
RETCODEO=0 | Sets online return code |
---|---|
RETCODEB=4 | Sets batch (single user) return code |
CLASS=E | Error class; the message can be suppressed with the X'04' bit setting of the MSGCTL parameter |
AUDITER | Writes the message with line type ER to the audit trail |
COUNT | Increments the error count (ERCNT) parameter |
ECHO | Displays the line that caused the error |