Skip to content

Recursive type definiton throws UndefVarError in v1.12 (works on v1.10 and v1.11) #57030

@nickrobinson251

Description

@nickrobinson251

The following code works in versions 1.10 and v1.11 but throws an error in 1.12.0-DEV.1882

struct ConstantTypeImpl
    value::Any
    function ConstantTypeImpl(c::Any)
        return new(c)
    end
end

struct WrappedTypeImpl
    value::Type
    function WrappedTypeImpl(value::Type)
        new(value)
    end
end

struct _ParamPackedTypeImpl{T}
    value::Vector{T}
end

let
    var"#7#types" = Dict(:_constant => ConstantTypeImpl, :_wrapped => WrappedTypeImpl)

    var"#8#unboxed" = [var"#11#f" for (var"#11#f", var"#9#T") = var"#7#types" if isbitstype(var"#9#T")]

    var"#10#size" = maximum((sizeof(var"#7#types"[var"#11#f"]) for var"#11#f" = var"#8#unboxed"), init=0)

    var"#12#P"() = begin
            Union{Nothing, if :_constant in var"#8#unboxed"
                    Union{}
                else
                    ConstantTypeImpl
                end, if :_wrapped in var"#8#unboxed"
                    Union{}
                else
                    WrappedTypeImpl
                end, if :_packed in var"#8#unboxed"
                    Union{}
                else
                    _ParamPackedTypeImpl{DBType}
                end}
        end

    struct DBType <: Any
        tag::UInt8
        bits::NTuple{var"#10#size", UInt8}
        ptrs::var"#12#P"()
    end
end
julia> include("repro.jl")
ERROR: LoadError: UndefVarError: `DBType` not defined in `Main`
Suggestion: add an appropriate import or assignment. This global was declared but not assigned.
Stacktrace:
 [1] (::var"#10#11"{Vector{Symbol}})()
   @ Main ~/repro.jl:38
 [2] top-level scope
   @ ~/repro.jl:42
 [3] include(mapexpr::Function, mod::Module, _path::String)
   @ Base ./Base.jl:301
 [4] top-level scope
   @ REPL[1]:1
in expression starting at /Users/nickr/repro.jl:19

git bisect points to 435516d / #56497 (cc @Keno)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions