From ddd29057e48a5b309726750e3daf78bfd073038e Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 4 Sep 2024 13:25:37 -0700 Subject: Fix extension override behavior, and disallow extension on interface types. (#4977) * Add a test to ensure extension does not override existing conformance. * Fix doc. * Update documentation. * Fix doc. * Add diagnostic test. --- source/slang/slang-check-decl.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (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 5654ac7a6..e5e8e8acc 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -8246,7 +8246,12 @@ namespace Slang if (auto targetDeclRefType = as(decl->targetType)) { // Attach our extension to that type as a candidate... - if (auto aggTypeDeclRef = targetDeclRefType->getDeclRef().as()) + if (targetDeclRefType->getDeclRef().as()) + { + getSink()->diagnose(decl->targetType.exp, Diagnostics::invalidExtensionOnInterface, decl->targetType); + return; + } + else if (auto aggTypeDeclRef = targetDeclRefType->getDeclRef().as()) { auto aggTypeDecl = aggTypeDeclRef.getDecl(); @@ -8303,6 +8308,7 @@ namespace Slang // to extend. // decl->targetType = CheckProperType(decl->targetType); + _validateExtensionDeclTargetType(decl); _validateExtensionDeclMembers(decl); @@ -9188,13 +9194,13 @@ namespace Slang // look up extensions based on what would be visible to that // module. // - // We need to consider the extensions declared in the module itself, + // Extensions declared in the module itself should have already + // been registered when we check them, but we still need to bring // along with everything the module imported. // // Note: there is an implicit assumption here that the `importedModules` // member on the `SharedSemanticsContext` is accurate in this case. // - _addCandidateExtensionsFromModule(m_module->getModuleDecl()); for( auto moduleDecl : this->importedModulesList ) { _addCandidateExtensionsFromModule(moduleDecl); -- cgit v1.2.3