marius311 / CompositeStructs.jl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regression with parametric types

mhinsch opened this issue · comments

This used to work but doesn't any more:

using CompositeStructs

struct A{T}
    x :: T
end

@composite struct B     
    A{B}...
end

This is the error message I get:

LoadError: UndefVarError: `B` not defined
in expression starting at In[3]:1

Stacktrace:
  [1] reconstruct_type(__module__::Module, typevars::Vector{Any}, s::Symbol)
    @ CompositeStructs ~/.julia/packages/CompositeStructs/ucvdr/src/CompositeStructs.jl:13
  [2] (::CompositeStructs.var"#1#2"{Module, Vector{Any}})(t::Type, x::Symbol)
    @ CompositeStructs ~/.julia/packages/CompositeStructs/ucvdr/src/CompositeStructs.jl:16
  [3] BottomRF
    @ ./reduce.jl:81 [inlined]
  [4] _foldl_impl(op::Base.BottomRF{CompositeStructs.var"#1#2"{Module, Vector{Any}}}, init::Type, itr::Vector{Any})
    @ Base ./reduce.jl:58
  [5] foldl_impl
    @ ./reduce.jl:48 [inlined]
  [6] mapfoldl_impl(f::typeof(identity), op::CompositeStructs.var"#1#2"{Module, Vector{Any}}, nt::Type, itr::Vector{Any})
    @ Base ./reduce.jl:44
  [7] mapfoldl(f::Function, op::Function, itr::Vector{Any}; init::Type)
    @ Base ./reduce.jl:170
  [8] mapfoldl
    @ ./reduce.jl:170 [inlined]
  [9] #foldl#289
    @ ./reduce.jl:193 [inlined]
 [10] reconstruct_type(__module__::Module, typevars::Vector{Any}, ex::Expr)
    @ CompositeStructs ~/.julia/packages/CompositeStructs/ucvdr/src/CompositeStructs.jl:16
 [11] reconstruct_fields_and_docstrings(__module__::Module, typevars::Vector{Any}, ex::Expr)
    @ CompositeStructs ~/.julia/packages/CompositeStructs/ucvdr/src/CompositeStructs.jl:52
 [12] var"@composite"(__source__::LineNumberNode, __module__::Module, ex::Any)
    @ CompositeStructs ~/.julia/packages/CompositeStructs/ucvdr/src/CompositeStructs.jl:91

The fix seems to be trivial, though. Just insert the following after line 81:

    push!(ParentTypeArgsStripped, ParentName)

Ok, that solution wasn't one, but I think I found it. Will send a pull request shortly.