Type assertion for parametric constructors behaves strangely

In your type declaration:

… the type parameter T is restricted to subtype Real:

A{2} fails with a TypeError because 2 doesn’t subtype Real. In fact, 2 is not a type at all.

“Constructors” are merely callable objects (objects with methods) that happen to be types: Constructors are just callable objects.

Note the TypeError gets thrown before an attempt to call the constructor could happen. Example:

julia> struct A{T<:Real, N} end

julia> A{2}
ERROR: TypeError: in A, in T, expected T<:Real, got a value of type Int64
4 Likes