Please enable JavaScript to view this site.

 

Navigation: Macros > Macro Language > Compiler Messages > Errors

Spurious return in typed function

Scroll Prev Up Next More

This compiler error occurs if the body of one of a typed user-defined functions contains more than one return instruction.

 

For example.

// user-defined function
function getConcatenatedDateString(nDate1 nDate2) : s
begin
    if MonthOf(nDate1) == MonthOf(nDate2)
        return EvalToken(nDate1, ', [d]-') + EvalToken(nDate2, '[d] [Mmmm]')
    else
        return EvalToken(nDate1, ', [d] [Mmmm]-') + EvalToken(nDate2, '[d] [Mmmm]')
    endif
end
 
// main body of the macro
var
   nRunDate nStartDate
begin
   // do some processing
   sResult = getConcatenatedDateString(nRunDate, nStartDate) 
end

A typed user-defined function must contain one, and only one, return instruction, and the second return, above, will trigger the present message.

 

Solution

 

The solution to the present message is:

 

1.Declare a variable of the correct type, local to that user-defined function, such as sConcatenated.

2.Replace every return in the function by "sConcatenated =" (do not include the quotation marks).

3.Add a final instruction, at the very end of the macro, returning the value calculated for sConcatenated.

 

Below is the corrected macro, showing where each of the 3 above points were applied.

// user-defined function
function getConcatenatedDateString(nDate1 nDate2) : s
var
   sConcatenated
begin
    if MonthOf(nDate1) == MonthOf(nDate2)
        sConcatenated = EvalToken(nDate1, ', [d]-') + EvalToken(nDate2, '[d] [Mmmm]')
    else
        sConcatenated = EvalToken(nDate1, ', [d] [Mmmm]-') + EvalToken(nDate2, '[d] [Mmmm]')
    endif
   // at the very end of the function
 return sConcatenated
end

See also: Spurious return in void function and Improperly placed return in user-defined macro function.

 


Topic 110205, last updated on 15-Oct-2026