summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-10-04 15:21:17 -0700
committerGitHub <noreply@github.com>2022-10-04 15:21:17 -0700
commit364e43264b9f69957ddaed8890392d82fb25c822 (patch)
treeaa4d9b6a90ddf398c12f7cce6499e3946d8ffeb1 /source/slang/slang-check-decl.cpp
parent8b1daa68a5ff1398cdf130aacad32d2e5646d1eb (diff)
Fix `ApplyExtensionToType` on own type being extended. (#2430)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
-rw-r--r--source/slang/slang-check-decl.cpp10
1 files changed, 9 insertions, 1 deletions
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<ExtensionDecl>();
-
auto constraintSubst = trySolveConstraintSystem(&constraints, DeclRef<Decl>(extGenericDecl, nullptr).as<GenericDecl>());
if (!constraintSubst)
{