API reference

Public

CheckConcreteStructs.all_concreteMethod
all_concrete(T::Type; verbose=true)

Return true if type T has only concretely-typed fields.

If verbose=true, any field with an abstract type will display a warning.

Examples

Types with abstract fields:

julia> using CheckConcreteStructs

julia> struct Bad1; x; end  # missing annotation

julia> all_concrete(Bad1; verbose=false)
false

julia> struct Bad2; x::AbstractVector; end  # abstract container

julia> all_concrete(Bad2; verbose=false)
false

julia> struct Bad3; x::Vector{<:Real}; end  # abstract element type

julia> all_concrete(Bad3; verbose=false)
false

julia> struct Bad4; x::Array{Float64}; end  # not enough type parameters

julia> all_concrete(Bad4; verbose=false)
false

Types with only concrete fields:

julia> using CheckConcreteStructs

julia> struct Good1; x::Vector{Float64}; end

julia> all_concrete(Good1)
true

julia> struct Good2{T<:Real}; x::Vector{T}; end

julia> all_concrete(Good2)
true

julia> struct Good3{T<:Real,V<:AbstractVector{T}}; x::V; end

julia> all_concrete(Good3)
true
source
CheckConcreteStructs.all_concreteMethod
all_concrete(M::Module; verbose=true)

Return true if every type defined inside the module M has only concretely-typed fields.

If verbose=true, any field with an abstract type will display a warning.

Warning

This function does not handle submodules yet.

source
CheckConcreteStructs.@check_concreteMacro
@check_concrete struct MyType
    # fields
end

Check that every field of a struct definition is concretely typed, throw an error if that is not the case.

Examples

Types with abstract fields:

julia> using CheckConcreteStructs

julia> @check_concrete struct Bad1; x; end  # missing annotation
ERROR: AbstractFieldError in struct `Bad1`: field `x` with declared type `Any` is not concretely typed.

julia> @check_concrete struct Bad2; x::AbstractVector; end  # abstract container
ERROR: AbstractFieldError in struct `Bad2`: field `x` with declared type `AbstractVector` is not concretely typed.

julia> @check_concrete struct Bad3; x::Vector{<:Real}; end  # abstract element type
ERROR: AbstractFieldError in struct `Bad3`: field `x` with declared type `Vector{<:Real}` is not concretely typed.

julia> @check_concrete struct Bad4; x::Array{Float64}; end  # not enough type parameters
ERROR: AbstractFieldError in struct `Bad4`: field `x` with declared type `Array{Float64}` is not concretely typed.

Types with only concrete fields:

julia> using CheckConcreteStructs

julia> @check_concrete struct Good1; x::Vector{Float64}; end
true

julia> @check_concrete struct Good2{T<:Real}; x::Vector{T}; end
true

julia> @check_concrete struct Good3{T<:Real,V<:AbstractVector{T}}; x::V; end
true
source

Private