From 39522159c245e32a99cfdc47f03236f7028f5c61 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 26 Feb 2024 17:00:31 -0800 Subject: Allow default values for `extern` symbols. (#3632) * Allow default values for `extern` symbols. * Fix. * Fix test. --- source/slang/slang-check-decl.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 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 25f535825..5a9559ce6 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1478,11 +1478,6 @@ namespace Slang } else { - if (varDecl->hasModifier()) - { - getSink()->diagnose(initExpr, Diagnostics::externValueCannotHaveInitializer); - } - initExpr = CheckExpr(initExpr); // TODO: We might need some additional steps here to ensure @@ -1850,7 +1845,7 @@ namespace Slang varDecl->initExpr = CompleteOverloadCandidate(overloadContext, *overloadContext.bestCandidate); } } - if (auto elementType = getBufferElementType(varDecl->getType())) + if (auto elementType = getConstantBufferElementType(varDecl->getType())) { if (doesTypeHaveTag(elementType, TypeTag::Incomplete)) { @@ -5166,6 +5161,13 @@ namespace Slang return false; } + static bool _doesTypeDeclHaveDefinition(ContainerDecl* decl) + { + if (auto aggTypeDecl = as(decl)) + return aggTypeDecl->hasBody; + return false; + } + bool SemanticsVisitor::checkConformance( Type* subType, InheritanceDecl* inheritanceDecl, @@ -5244,7 +5246,8 @@ namespace Slang witnessTable = new WitnessTable(); witnessTable->baseType = superType; witnessTable->witnessedType = subType; - witnessTable->isExtern = parentDecl->hasModifier(); + witnessTable->isExtern = (!_doesTypeDeclHaveDefinition(parentDecl) + && parentDecl->hasModifier()); inheritanceDecl->witnessTable = witnessTable; } -- cgit v1.2.3