From 9e173baa58ad2167239008eab92d6489e8ef3fb5 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash@gmail.com>
Date: Sat, 20 Jul 2024 16:45:07 -0400
Subject: [PATCH] Make Core.TypeofUnion use the type method table

Ensures that adding or examining the methods of Type{Union{}} in the
method table returns the correct results.

Fixes #55187
---
 src/jltypes.c      | 7 +++++--
 test/reflection.jl | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/jltypes.c b/src/jltypes.c
index b8a81f94a7931..10b8bc937939e 100644
--- a/src/jltypes.c
+++ b/src/jltypes.c
@@ -3581,8 +3581,11 @@ void jl_init_types(void) JL_GC_DISABLED
                                        jl_emptysvec, 0, 0, 4);
 
     // all Kinds share the Type method table (not the nonfunction one)
-    jl_unionall_type->name->mt = jl_uniontype_type->name->mt = jl_datatype_type->name->mt =
-        jl_type_type_mt;
+    jl_unionall_type->name->mt =
+        jl_uniontype_type->name->mt =
+        jl_datatype_type->name->mt =
+        jl_typeofbottom_type->name->mt =
+            jl_type_type_mt;
 
     jl_intrinsic_type = jl_new_primitivetype((jl_value_t*)jl_symbol("IntrinsicFunction"), core,
                                              jl_builtin_type, jl_emptysvec, 32);
diff --git a/test/reflection.jl b/test/reflection.jl
index 895da80e03c75..ef940b034a2e1 100644
--- a/test/reflection.jl
+++ b/test/reflection.jl
@@ -1296,3 +1296,5 @@ end
 
 @test Base.infer_return_type(code_lowered, (Any,)) == Vector{Core.CodeInfo}
 @test Base.infer_return_type(code_lowered, (Any,Any)) == Vector{Core.CodeInfo}
+
+@test methods(Union{}) == Any[m.method for m in Base._methods_by_ftype(Tuple{Core.TypeofBottom, Vararg}, 1, Base.get_world_counter())] # issue #55187