TypeInfo (version 1.38.0)

checkReturnValue: Verify the return value from the function has the appropriate type

Description

This function is the counterpart to checkArgs in the type validation for an R function. When called, either implicitly or explicitly when the function returns, it attempts to determine whether the value being returned by the function call is valid relative to the type information of the function and the call itself. Specifically, it uses the signature of the current call to the function if it is available (returned by checkArgs) to see if it has a specified return type. If so, it compares the return value to that. Otherwise, it checks to see if the return type for the overall type info object (not just the specific type signature for the call) is specified and then uses that to validate the type. If neither is specified, then the value is not validated and the value returned.

Usage

checkReturnValue(returnType, returnJump, sig, f = sys.function(-1))

Arguments

returnType
the specifiedtype of the return value.
returnJump
this is a very special value which is a call to return the value of value. It must be explicitly given in the call to checkReturnValue and is used to ensure that the return from checkReturnValue returns from the calling function also in the case that the value is valid. This is a piece of magic in R that is very powerful using the lazy evaluation of the arguments that allows us to return from the place that the return call was specified.
sig
the signature corresponding to the call of the function f. This should have a returnType slot that contains class information or an expression. Otherwise, the value is taken from the TypeSpecification-class object for the entire function and its returnType slot.
f
the function object whose return value is to be validated. It is from this that we get the type info via typeInfo.

Value

If the validation takes place and is successful or simply doesn't take place because no returnType is available, the return value is value. Otherwise, if the validation fails, an error is raised.

See Also

checkArgs TypeSpecification-class