#CartesianGrid is defined like this
struct CartesianGrid{Dim,T} <: Mesh{Dim,T}
#code
end
#This function throws error
function AbstractPlotting.plot!(grid::CartesianGrid{Dim,T}) where {Dim,T}
#code
end
throws error LoadError: too many parameters for type
My understanding is that I'm specifying two parameters Dim
and T
whereas only one/none should be possible according to this error. Why is it so?
https://discourse.julialang.org/t/tricky-too-many-parameters-for-type-error/25182/6 this is also about the same error but I'm unable to understand the solution there.
Could you give a runnable example that replciates the error you're getting?
E.g. how is Mesh
defined?
Whatever is causing the error you're experiencing isn't actually caused by the code you've written here:
julia> abstract type Mesh{Dim, T} end
julia> struct CartesianGrid{Dim, T} <: Mesh{Dim, T} end
julia> f(::CartesianGrid{Dim, T}) where {Dim, T} = (Dim, T)
f (generic function with 1 method)
julia> f(CartesianGrid{2, Float64}())
(2, Float64)
abstract type Mesh{Dim,T} <: Domain{Dim,T} end
abstract type Domain{Dim,T} end
#Code to reproduce the error
#CartesianGrid is defined in Meshes
using Meshes
using GLMakie
@recipe(CartesianGrid) do scene
Attributes(
seriescolor = :black,
)
end
function AbstractPlotting.plot!(grid::CartesianGrid{Dim,T}) where {Dim,T}
#code
end
Thanks for the quick reply
Should I look into the source code of Meshes; and what could be the possible mistake leading to this error?
It looks like the reason this is happening is that CartesianGrid
isn't a struct, it's actually this:
julia> CartesianGrid
Combined{cartesiangrid, ArgType} where ArgType
It only has one type parameter, not two.
Aha! it looks like it's the recipe
that screwed things up:
julia> @macroexpand @recipe(CartesianGrid) do scene
Attributes(
seriescolor = :black,
)
end
quote
#= /home/mason/.julia/packages/AbstractPlotting/cfp2m/src/recipes.jl:130 =#
cartesiangrid() = begin
#= /home/mason/.julia/packages/AbstractPlotting/cfp2m/src/recipes.jl:130 =#
AbstractPlotting.not_implemented_for(cartesiangrid)
end
#= /home/mason/.julia/packages/AbstractPlotting/cfp2m/src/recipes.jl:131 =#
const CartesianGrid{ArgType} = AbstractPlotting.Combined{cartesiangrid, ArgType}
[...]
See here, it defined a new CartesianGrid
that shadowed Meshes.CartesianGrid
in your module
You could write
function AbstractPlotting.plot!(grid::Meshes.CartesianGrid{Dim,T}) where {Dim,T}
#code
end
Woah, thanks for the solution!
It works now and also the reason behind the error is clear! :+1:
Glad I could help :grinning:
You can also ask this sort of questions in #meshes.jl channel. @Júlio Hoffimann is a main maintainer of the corresponding packages and usually very responsive.
Last updated: Dec 28 2024 at 04:38 UTC