RecipesBase.jl icon indicating copy to clipboard operation
RecipesBase.jl copied to clipboard

`@userplot` struct and function name can clash

Open bencottier opened this issue 3 years ago • 0 comments

The struct name declared for a @userplot is not constrained AFAIK, so it can clash with the function name that is generated as a result.

MWE:

julia> using RecipesBase

julia> @userplot myplot
        myplot! (generic function with 2 methods)

julia> myplot(1:3)
myplot(1:3)

This is a problem in practice when the @recipe can take just one positional argument, e.g.

julia> @recipe function f(plot::myplot)
           x = plot.args[1]
           @series begin
               x, 2x
           end
       end

julia> myplot(1:3)
myplot(1:3)  # returns struct instead of Plot

The docs implicitly suggest using camel case for the struct name, but a user shouldn't have to know how the macro works to avoid this issue - detecting the problem and throwing an error would be more helpful.

bencottier avatar Oct 29 '21 12:10 bencottier