Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError in getproperty on container types #32

Open
akirakyle opened this issue Nov 18, 2024 · 0 comments
Open

TypeError in getproperty on container types #32

akirakyle opened this issue Nov 18, 2024 · 0 comments

Comments

@akirakyle
Copy link

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}
    end
end

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant