From 63ab71618bd5c9d91bf129b09de1806232999093 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash@gmail.com>
Date: Fri, 29 Sep 2023 18:41:22 +0200
Subject: [PATCH] avoid limiting Type{Any} to Type

Fix #51510
---
 base/compiler/typelimits.jl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl
index 44ddbf8dcba38..dc68f026e6b8f 100644
--- a/base/compiler/typelimits.jl
+++ b/base/compiler/typelimits.jl
@@ -135,8 +135,8 @@ function _limit_type_size(@nospecialize(t), @nospecialize(c), sources::SimpleVec
                 ct = Union{}
             end
             Qt = __limit_type_size(tt, ct, sources, depth + 1, 0)
-            Qt === Any && return Type
             Qt === tt && return t
+            Qt === Any && return Type
             # Can't form Type{<:Qt} just yet, without first make sure we limited the depth
             # enough, since this moves Qt outside of Type for is_derived_type_from_any
             Qt = __limit_type_size(tt, ct, sources, depth + 2, 0)