Skip to content

Improve error message when attempting to instantiate unionall #38178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jakobnissen opened this issue Oct 26, 2020 · 0 comments
Open

Improve error message when attempting to instantiate unionall #38178

jakobnissen opened this issue Oct 26, 2020 · 0 comments

Comments

@jakobnissen
Copy link
Member

jakobnissen commented Oct 26, 2020

A user might try something like this:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant