Expronicon.jl
Expronicon.jl copied to clipboard
Support isbits/isbitstype for variants?
using Expronicon.ADT: @adt
julia> @adt D begin
D1
D2(::Int)
end
julia> isbits(D.D1)
ERROR: ArgumentError: invalid variant type
The issue comes from:
julia> @less isbits(D.D1)
isbits(@nospecialize x) = (@_pure_meta; typeof(x).flags & 0x8 == 0x8)
# this works:
# getfield(D, :flags) & 0x8
Julia base might not consider much about overloading getproperty
for DataTypes (this is also generally
not that good). Incompatibility like above could happen unexpectedly. Maybe patch this in Expronicon.jl?
which version of Julia are you using? this works for me on 1.9 & 1.8
julia> @adt D begin
D1
D2(::Int)
end
julia> isbits(D.D1)
true
we currently forward all DataType
fields and treat those as reserved variant names, because if one follows the camel case convention, they will never use these field names anyway. these names are hidden in propertynames
so user won't see them in auto-completion, but anything defined on DataType
should in principle compatible with this implementation.