Stream: helpdesk (published)

Topic: ✔ Hard to debug constructor error


view this post on Zulip Michael Fiano (Aug 09 2022 at 22:02):

I've seen this quite a few times, and it is very hard to figure out what the compiler is trying to tell me. I have no idea why the name is gensymed, when methods shows me exactly what I supplied. There are no other constructor methods for this type, just this one:

struct Cellular{N} <: AbstractSampler{N}
    random_state::RandomState
    table::Vector{Float64}
    jitter::Float64
    metric::DistanceMetric
    cell_func::CellFunction
    function Cellular{N}(;
        seed::Seed=nothing,
        jitter::Real=1.0,
        metric::DistanceMetric=Euclidean,
        cell_func::CellFunction=F1,
    ) where {N}
        rs = RandomState(seed)
        table = rand(rs.rng, Uniform(-1.0, 1.0), table_size(Val(N)))
        new{N}(rs, table, jitter, metric, cell_func)
    end
end
(CoherentNoise) julia> s = Cellular{2}(seed=1)
ERROR: MethodError: no method matching (::CoherentNoise.Noise.CellularNoise.var"#_#1#2")(::Int64, ::Float64, :
:Type{Euclidean}, ::Type{F1}, ::Type{Cellular{2}})
Closest candidates are:
  (::CoherentNoise.Noise.CellularNoise.var"#_#1#2")(::Union{Nothing, Integer}, ::Real, ::CoherentNoise.Noise.C
ellularNoise.DistanceMetric, ::CoherentNoise.Noise.CellularNoise.CellFunction, ::Type{Cellular{N}}) where N at
 ~/projects/Julia/CoherentNoise/src/noise_cellular.jl:32
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

view this post on Zulip Mason Protter (Aug 09 2022 at 22:19):

Hard to say without a reproducer. Have you tried making a minimal working example?

view this post on Zulip Michael Fiano (Aug 09 2022 at 22:20):

It seems this was due to specifying default values that are types rather than instances of the asserted type.

view this post on Zulip Michael Fiano (Aug 09 2022 at 22:20):

Such a confusing error message

view this post on Zulip Notification Bot (Aug 09 2022 at 22:46):

Michael Fiano has marked this topic as resolved.


Last updated: Nov 22 2024 at 04:41 UTC