Expronicon.jl icon indicating copy to clipboard operation
Expronicon.jl copied to clipboard

Support isbits/isbitstype for variants?

Open thautwarm opened this issue 1 year ago • 1 comments

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?

thautwarm avatar Mar 19 '23 14:03 thautwarm

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.

Roger-luo avatar Mar 19 '23 20:03 Roger-luo