never-returns (primitive)
Package: CURL.LANGUAGE.CORE-TYPES

The return type of a procedure that never returns.

Description

When used as a return type of a procedure or method, it indicates that the code will not return to the caller when invoked (i.e. that it can only terminate through a throw, error, exit, or the like).

A proc declared to return never-returns will not be allowed to contain return statements and must always terminate in an expression of type never-returns, or else the compiler will generate an appropriate syntax error.

The compile-time type of conditional expressions such as if, switch, type-switch will be based on only those conditional branches whose compile-time type is not never-returns. If all of the branches do not return, then the compile-time type of the expression is never-returns. For instance, in the example below declaring not-odd-error as never-returns allows it to be used in the else clause without preventing the if from producing a value.

Functions that are intended to always throw an error or exception or which otherwise do not return control to the caller should be declared with the never-returns return type.

The never-returns type may not be used in type declarations for variables, fields or parameters.

Example


Example: Use of never-returns return type.
{define-proc {not-odd-error i:int}:never-returns
    {error {format "%s is not odd", i}}
}
{define-proc {assert-odd val:int}:int
    {return
        {if {bit-and val, 1} == 1 then
            val
         else
            {not-odd-error val}
        }
    }
}