When using bits as type parameters they are regarded a subtype of Any

Hi all,
using julia 1.6.1 there is currently an inconsistency when using bits (i.e. anything which is a bit-type) as type-parameters and when comparing bits directly with types.

julia> f(::Type{Tuple{T1}}) where T1 <: Any = :hi
f (generic function with 1 method)

julia> f(Tuple{1})

julia> 1 <: Any
ERROR: TypeError: in <:, expected Type, got a value of type Int64
 [1] top-level scope
   @ REPL[3]:1

The one or the other does not make sense, either 1 <: Any or not. It should not make a difference whether it is a type-parameter or not.
Or should it?

I can see why this feels inconsistent. From the practical point of view, isbits in type parameter enables nice things such as Matrix = Array{T, 2}, and that a distinguished syntax is annoying to remember?

thanks for your remark. Yes, I also use this quite a lot and a recent package, in my case it simplifies the syntax nicely.

Do you know whether there is an github issue which discussed this?
If it was done intentionally, I bet there was more discussion around it.

My current workaround is to just add another helper function to dispatch the parameter types normally, where everything works nicely again. So not a blocking point for so far luckily, but still it would be nice to address this inconsistency. At least with some documentaion added to the official julia docs.

I would prefer to get an error, since using <: on something else than types is very likely to be a bug in my code. The earlier caught, the better.

You can always do something like

mysubtype(::Type{T}, ::Type{S}) where {T,S} = T <: S
mysubtype(_, ::Type{Any}) = true
mysubtype(_, _) = false

but such catch-all methods are generally not considered good style in Julia. Few functions should have methods for everything.

1 Like