Skip to content

Commit

Permalink
improve error message for invoke (#51831)
Browse files Browse the repository at this point in the history
This is effectively a type-assert, but the error message sounded
confusing and internal without the context of what it got and what it
expected to get.

Refs: #51826

after:
`ERROR: TypeError: in invoke: argument type error, expected Tuple{Int64,
Vararg{Int64}}, got a value of type Tuple{DataType, Int64}`
  • Loading branch information
vtjnash committed Oct 25, 2023
1 parent bde62ad commit 193ead2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ JL_CALLABLE(jl_f_invoke)
if (!jl_is_tuple_type(jl_unwrap_unionall(args[1])))
jl_type_error("invoke", (jl_value_t*)jl_anytuple_type_type, args[1]);
if (!jl_tuple_isa(&args[2], nargs - 2, (jl_datatype_t*)argtypes))
jl_error("invoke: argument type error");
jl_type_error("invoke: argument type error", argtypes, jl_f_tuple(NULL, &args[2], nargs - 2));
jl_value_t *res = jl_gf_invoke(argtypes, args[0], &args[2], nargs - 1);
JL_GC_POP();
return res;
Expand Down
4 changes: 2 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5188,9 +5188,9 @@ let x = 1
@noinline g18444(a) = (x += 1; a[])
f18444_1(a) = invoke(sin, Tuple{Int}, g18444(a))
f18444_2(a) = invoke(sin, Tuple{Integer}, g18444(a))
@test_throws ErrorException("invoke: argument type error") f18444_1(Ref{Any}(1.0))
@test_throws "TypeError: in invoke: argument type error, expected" f18444_1(Ref{Any}(1.0))
@test x == 2
@test_throws ErrorException("invoke: argument type error") f18444_2(Ref{Any}(1.0))
@test_throws "TypeError: in invoke: argument type error, expected" f18444_2(Ref{Any}(1.0))
@test x == 3
@test f18444_1(Ref{Any}(1)) === sin(1)
@test x == 4
Expand Down

0 comments on commit 193ead2

Please sign in to comment.