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 +++++++++- source/slang/slang.natvis | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'source') 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) { diff --git a/source/slang/slang.natvis b/source/slang/slang.natvis index 6c8f15ec9..ee868be62 100644 --- a/source/slang/slang.natvis +++ b/source/slang/slang.natvis @@ -282,6 +282,8 @@ {nameAndLoc.name->text}: {astNodeType} {astNodeType} + nameAndLoc.name->text + parentDecl (Slang::ContainerDecl*)&astNodeType (Slang::ExtensionDecl*)&astNodeType (Slang::StructDecl*)&astNodeType @@ -322,6 +324,7 @@ (Slang::EmptyDecl*)&astNodeType (Slang::SyntaxDecl*)&astNodeType (Slang::DeclGroup*)&astNodeType + (Slang::DeclBase*)this,nd @@ -369,7 +372,7 @@ (Slang::EmptyDecl*)&astNodeType (Slang::SyntaxDecl*)&astNodeType (Slang::DeclGroup*)&astNodeType - (Slang::DeclBase*)this,nd + (Slang::Decl*)this,nd @@ -473,8 +476,6 @@ {nameAndLoc.name}: {astNodeType} - nameAndLoc.name - parentDecl members -- cgit v1.2.3