You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
julia> struct Foo{X} end
julia> foo(::Type{<:Foo{X}}, x) where X = Foo{X}(x)
foo (generic function with 2 methods)
julia> foo(Foo, 2)
ERROR: MethodError: no method matching foo(::Type{Foo}, ::Int64)
Closest candidates are:
foo(::Type{var"#s17"} where var"#s17"<:Foo{X}, ::Any) where X at REPL[2]:1
Stacktrace:
[1] top-level scope at REPL[4]:1
julia> Foo <: Foo{X} where X
true
And be confused. If Foo <: Foo{X} where X, why does it raise a method error? I ran into it a few days ago (#38111 ), and @juliohm ran into it today. As Jeff Bezanson explained, the reason is that, since foo needs to actually instantiate a Foo, the type parameter X needs to be concrete.
It would be nice if the error message was better. I'm not sure where the error message should be, though.
Edit: Although the mistake may seem obvious in this minimal example, and therefore not need a detailed error message, it's unfortunately not hard to run into this problem with much more complicated type signatures.
The text was updated successfully, but these errors were encountered:
A user might try something like this:
And be confused. If
Foo <: Foo{X} where X
, why does it raise a method error? I ran into it a few days ago (#38111 ), and @juliohm ran into it today. As Jeff Bezanson explained, the reason is that, sincefoo
needs to actually instantiate aFoo
, the type parameterX
needs to be concrete.It would be nice if the error message was better. I'm not sure where the error message should be, though.
Edit: Although the mistake may seem obvious in this minimal example, and therefore not need a detailed error message, it's unfortunately not hard to run into this problem with much more complicated type signatures.
The text was updated successfully, but these errors were encountered: