From f048adb6f22baf7c9c395f76fdd82838028e92cd Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sun, 27 Jul 2025 21:02:43 -0400 Subject: [PATCH 1/2] add builtin function name to error --- src/method.c | 2 +- test/core.jl | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/method.c b/src/method.c index 8220178964333..dd851bc12a5cd 100644 --- a/src/method.c +++ b/src/method.c @@ -1299,7 +1299,7 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata, } ft = jl_rewrap_unionall(ft, argtype); if (!external_mt && !jl_has_empty_intersection(ft, (jl_value_t*)jl_builtin_type)) // disallow adding methods to Any, Function, Builtin, and subtypes, or Unions of those - jl_error("cannot add methods to a builtin function"); + jl_errorf("cannot add methods to a builtin function `%s`", jl_symbol_name(name)); m = jl_new_method_uninit(module); m->external_mt = (jl_value_t*)external_mt; diff --git a/test/core.jl b/test/core.jl index 3d79802e33a87..edeceefb50a96 100644 --- a/test/core.jl +++ b/test/core.jl @@ -2661,13 +2661,16 @@ struct D14919 <: Function; end @test B14919()() == "It's a brand new world" @test C14919()() == D14919()() == "Boo." -let ex = ErrorException("cannot add methods to a builtin function") +let ex_t = ErrorException, ex_r = r"cannot add methods to a builtin function" for f in (:(Core.Any), :(Core.Function), :(Core.Builtin), :(Base.Callable), :(Union{Nothing,F} where F), :(typeof(Core.getfield)), :(Core.IntrinsicFunction)) - @test_throws ex @eval (::$f)() = 1 + @test_throws ex_t @eval (::$f)() = 1 + @test_throws ex_r @eval (::$f)() = 1 end - @test_throws ex @eval (::Union{Nothing,F})() where {F<:Function} = 1 + @test_throws ex_t @eval (::Union{Nothing,F})() where {F<:Function} = 1 + @test_throws ex_r @eval (::Union{Nothing,F})() where {F<:Function} = 1 for f in (:(Core.getfield),) - @test_throws ex @eval $f() = 1 + @test_throws ex_t @eval $f() = 1 + @test_throws ex_r @eval $f() = 1 end end From 32bcffad7aac4aaeb73fd712debbd5b2a8b68fce Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 28 Jul 2025 09:14:34 -0400 Subject: [PATCH 2/2] rm "a" --- src/method.c | 4 ++-- test/core.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/method.c b/src/method.c index dd851bc12a5cd..c33b343742dc8 100644 --- a/src/method.c +++ b/src/method.c @@ -1220,7 +1220,7 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata, // jl_value_t **ttypes = { jl_builtin_type, jl_tparam0(jl_anytuple_type) }; // jl_value_t *invalidt = jl_apply_tuple_type_v(ttypes, 2); // Tuple{Union{Builtin,OpaqueClosure}, Vararg} // if (!jl_has_empty_intersection(argtype, invalidt)) - // jl_error("cannot add methods to a builtin function"); + // jl_error("cannot add methods to builtin function"); //} assert(jl_is_linenode(functionloc)); @@ -1299,7 +1299,7 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata, } ft = jl_rewrap_unionall(ft, argtype); if (!external_mt && !jl_has_empty_intersection(ft, (jl_value_t*)jl_builtin_type)) // disallow adding methods to Any, Function, Builtin, and subtypes, or Unions of those - jl_errorf("cannot add methods to a builtin function `%s`", jl_symbol_name(name)); + jl_errorf("cannot add methods to builtin function `%s`", jl_symbol_name(name)); m = jl_new_method_uninit(module); m->external_mt = (jl_value_t*)external_mt; diff --git a/test/core.jl b/test/core.jl index edeceefb50a96..78d777c6ed84c 100644 --- a/test/core.jl +++ b/test/core.jl @@ -2661,7 +2661,7 @@ struct D14919 <: Function; end @test B14919()() == "It's a brand new world" @test C14919()() == D14919()() == "Boo." -let ex_t = ErrorException, ex_r = r"cannot add methods to a builtin function" +let ex_t = ErrorException, ex_r = r"cannot add methods to builtin function" for f in (:(Core.Any), :(Core.Function), :(Core.Builtin), :(Base.Callable), :(Union{Nothing,F} where F), :(typeof(Core.getfield)), :(Core.IntrinsicFunction)) @test_throws ex_t @eval (::$f)() = 1 @test_throws ex_r @eval (::$f)() = 1