From 364e43264b9f69957ddaed8890392d82fb25c822 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 4 Oct 2022 15:21:17 -0700 Subject: Fix `ApplyExtensionToType` on own type being extended. (#2430) Co-authored-by: Yong He --- source/slang/slang-check-decl.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-check-decl.cpp') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index a7cd768b1..b18e1c4da 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -5226,9 +5226,17 @@ namespace Slang constraints.loc = extDecl->loc; constraints.genericDecl = extGenericDecl; + // Inside the body of an extension declaration, we may end up trying to apply that + // extension to its own target type. + // If we see that we are in that case, we can apply the extension declaration as - is, + // without any additional substitutions. + if (extDecl->targetType->equals(type)) + { + return extDeclRef; + } + if (!TryUnifyTypes(constraints, extDecl->targetType.Ptr(), type)) return DeclRef(); - auto constraintSubst = trySolveConstraintSystem(&constraints, DeclRef(extGenericDecl, nullptr).as()); if (!constraintSubst) { -- cgit v1.2.3