From 013bcf28da22fd569154bd9f98368e670fbeb873 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 25 Jan 2024 17:47:40 -0800 Subject: Fixes for `module` and `include`. (#3519) * Fix type checking of enum cases. * Allow decl to have same name as module. --------- Co-authored-by: Yong He --- source/slang/slang-check-decl.cpp | 10 ++++++++++ source/slang/slang-check-overload.cpp | 6 ++++++ 2 files changed, 16 insertions(+) (limited to 'source') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 0df9619b6..fe4a7d64c 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -528,6 +528,7 @@ namespace Slang } else if( auto enumCaseDeclRef = declRef.as() ) { + sema->ensureDecl(declRef.declRefBase, DeclCheckState::Checked); QualType qualType; qualType.type = getType(astBuilder, enumCaseDeclRef); qualType.isLeftValue = false; @@ -5117,6 +5118,8 @@ namespace Slang // TODO: Do we need/want to support generic cases some day? auto parentEnumDecl = as(decl->parentDecl); SLANG_ASSERT(parentEnumDecl); + + decl->type.type = DeclRefType::create(m_astBuilder, makeDeclRef(parentEnumDecl)); // The tag type should have already been set by // the surrounding `enum` declaration. @@ -5852,6 +5855,13 @@ namespace Slang } } + if (as(oldDecl) || as(newDecl)) + { + // It is allowed to have a decl whose name is the same as the module. + return SLANG_OK; + } + + // For all other flavors of declaration, we do not // allow duplicate declarations with the same name. // diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 2912a79b0..37c92a317 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -992,6 +992,12 @@ namespace Slang if(leftIsInterfaceRequirement != rightIsInterfaceRequirement) return int(leftIsInterfaceRequirement) - int(rightIsInterfaceRequirement); + // Any decl is strictly better than a module decl. + bool leftIsModule = (as(left.declRef) != nullptr); + bool rightIsModule = (as(right.declRef) != nullptr); + if(leftIsModule != rightIsModule) + return int(rightIsModule) - int(leftIsModule); + // If both are interface requirements, prefer to more derived interface. if (leftIsInterfaceRequirement && rightIsInterfaceRequirement) { -- cgit v1.2.3