You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I may have stumbled upon a bug with getproperty on accessing container types, although I suspect it's actually a missing convert in the constructor's definition. For example
using Moshi.Data:@data@data OptionVec{T} begin
None
struct Some
n::T
xs::Vector{Any}endend
A = OptionVec.Some{String}("hi", [1, 2])
A.xs
gives the error
ERROR: TypeError: in typeassert, expected Vector{Any}, got a value of type Vector{Int64}
Stacktrace:
[1] getproperty(value::Main.OptionVec.var"typeof(OptionVec)"{String}, name::Symbol)
@ Main.OptionVec ~/.julia/packages/Moshi/SEGHC/src/data/emit/getproperty.jl:21
[2] top-level scope
@ REPL[5]:1
This can obviously be fixed by just converting before the constructor OptionVec.Some{String}("hi", Any[1, 2]) but I would expect the constructor to automatically handle the conversion to the specified variant's type?
The text was updated successfully, but these errors were encountered:
After doing a macroexpand on a simple data type with Vector{Any}, I saw that the variant storage struct had an Any field instead of Vector{Any}, hence there was no automatic conversion from Vector{Int} to Vector{Any} on construction. The variant_fieldtypes however correctly shows Vector{Any}. This results is a mismatch in the typeassert in getproperty.
using Moshi.Data.Prelude
@data M beginV(Vector{Any})
end
v = M.V([5])
variant_fieldtypes(v) # => (Vector{Any},)dump(variant_storage(v))
Main.M.var"##Storage#V"##field#230: Array{Int64}((1,)) [5]getproperty(v, 1) # => TypeError in typeassert
The reason for this any is that it gives up when encountering an Any type parameter like in Vector{Any}. Removing this line gets the desired behavior for this example:
Any in typevars &&return Any # no need to specialize further
I don't quite understand what goes wrong though, the typeassert now is sometimes wrong in a different way, causing tests to fail. Probably related to self referencing data types?
julia>using Moshi
julia> r = Moshi.Match.Pattern.Row([]);
julia> r.xs
ERROR: TypeError:in typeassert, expected Vector{Moshi.Match.Pattern.var"typeof(Pattern)"}, got a value of type Vector{Any}
Stacktrace:
[1] getproperty(value::Moshi.Match.Pattern.var"typeof(Pattern)", name::Symbol)
@ Moshi.Match.Pattern a:\.julia\dev\Moshi\src\data\emit\getproperty.jl:21
julia>variant_fieldtypes(r)
(Vector{Moshi.Match.Pattern.var"typeof(Pattern)"},)
julia>dump(variant_storage(r))
Moshi.Match.Pattern.var"##Storage#Row"
xs:Array{Any}((0,))
I think I may have stumbled upon a bug with
getproperty
on accessing container types, although I suspect it's actually a missingconvert
in the constructor's definition. For examplegives the error
This can obviously be fixed by just converting before the constructor
OptionVec.Some{String}("hi", Any[1, 2])
but I would expect the constructor to automatically handle the conversion to the specified variant's type?The text was updated successfully, but these errors were encountered: