Skip to content
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

Inaccurate printing of TypeError message #35231

Closed
englhardt opened this issue Mar 23, 2020 · 2 comments
Closed

Inaccurate printing of TypeError message #35231

englhardt opened this issue Mar 23, 2020 · 2 comments
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@englhardt
Copy link

While the examples below are clear cases where the user did not RTFM, they are still confusing and we could improve the error message:

isa

julia> isa(1, Int64)
true
julia> isa(Int64, 1)
ERROR: TypeError: in isa, expected Type, got Int64
Stacktrace:
 [1] top-level scope at REPL[5]:1

Int64 is a Type so we should prompt that the user passed the value 1 instead of a Type:
Expected: ERROR: TypeError: in isa, expected Type, got 1.

Union

julia> Union{Real, nothing}
ERROR: TypeError: in Union, expected Type, got Nothing
Stacktrace:
 [1] top-level scope at REPL[8]:1

Similar to isa(Nothing, nothing) that yields a similar error.
Expected: ERROR: TypeError: in isa, expected Type, got nothing.

As far as I can see, this part of the string in the TypeError message is generated by the macro @nospecialize in Base.

julia> versioninfo()
Julia Version 1.5.0-DEV.494
Commit 59d7522eae (2020-03-23 03:46 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
@StefanKarpinski StefanKarpinski added the help wanted Indicates that a maintainer wants help on an issue or pull request label Mar 23, 2020
@jakobnissen
Copy link
Contributor

The behaviour is correct, no? In the first case, the function expects a Type for the second argument, and you passed it 1, which is indeed a Int64. In the second case, it expects a type, and gets nothing, an instance of Nothing.

Maybe it could be phrased better as:
in Union, expected an instance of Type, got an instance of Nothing
?

@StefanKarpinski
Copy link
Member

I think the issue is that the error messages, while accurate, could be clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants