TypeInfo (version 1.38.0)

hasParameterType: Functions to query existence of specific type information

Description

These functions and the associated methods are used to determine if a function has type specification for any of the parameters and also for the return type. These are used when rewriting the body of the function to support type checking (see rewriteTypeCheck). We use these predicate functions to determine if we have information about any parameter types and if not we do not add a check of the arguments (i.e. a call to checkArgs). Similarly, we determine if we have any information about the return type before adding a call to checkReturnValue.

They are used internally. They are exported in order to make them available for others to use in providing alternatives to this prototype implementation and also to overcome an anomoly in the callNextMethod() mechanism that appears to disappear when the generic is exported from the NAMESPACE.

Usage

hasParameterType(def)

Arguments

def
the object which is to be queried. This can be a function or a TypeSpecification-class instance which is typically extracted from the function. Generally, a user would pass the function to the function call and the resulting sequence of recursive method calls will occur.

Value

A logical value indicating if the object def “has” the relevant facet/property.

See Also

rewriteTypeCheck checkArgs checkReturnValue

Examples

Run this code

hasReturnType(SimultaneousTypeSpecification(
                       TypedSignature(x="integer", returnType = "duncan")))


# FALSE
hasReturnType(SimultaneousTypeSpecification(TypedSignature(x="integer")))

# TRUE
hasReturnType(SimultaneousTypeSpecification(returnType = "duncan"))

# TRUE
hasReturnType(ReturnTypeSpecification("duncan"))

hasReturnType(IndependentTypeSpecification(x = c("integer", "logical"),
                                           y  = "character",
                                           returnType = "duncan"))

hasReturnType(IndependentTypeSpecification(x = c("integer", "logical"),
                                           y  = "character"))

Run the code above in your browser using DataLab