diff options
| author | Yong He <yonghe@outlook.com> | 2024-09-04 13:25:37 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-04 13:25:37 -0700 |
| commit | ddd29057e48a5b309726750e3daf78bfd073038e (patch) | |
| tree | a054b99acb87d61ef4818dce5fa837ccfd050288 /source/slang/slang-check-decl.cpp | |
| parent | 56a3c028a6725e13a2ae3a724eaee05ad9f4802a (diff) | |
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.
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
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<DeclRefType>(decl->targetType)) { // Attach our extension to that type as a candidate... - if (auto aggTypeDeclRef = targetDeclRefType->getDeclRef().as<AggTypeDecl>()) + if (targetDeclRefType->getDeclRef().as<InterfaceDecl>()) + { + getSink()->diagnose(decl->targetType.exp, Diagnostics::invalidExtensionOnInterface, decl->targetType); + return; + } + else if (auto aggTypeDeclRef = targetDeclRefType->getDeclRef().as<AggTypeDecl>()) { 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); |
