summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-26 17:00:31 -0800
committerGitHub <noreply@github.com>2024-02-26 17:00:31 -0800
commit39522159c245e32a99cfdc47f03236f7028f5c61 (patch)
tree4ae93fb32f267f7caa5ce55a6a52aac9f1f33bdd /source/slang/slang-check-decl.cpp
parent1d8e93cd434f0c7acbb6db747b32c3a3720c5c2e (diff)
Allow default values for `extern` symbols. (#3632)
* Allow default values for `extern` symbols. * Fix. * Fix test.
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
-rw-r--r--source/slang/slang-check-decl.cpp17
1 files changed, 10 insertions, 7 deletions
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<ExternModifier>())
- {
- 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<AggTypeDecl>(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<ExternModifier>();
+ witnessTable->isExtern = (!_doesTypeDeclHaveDefinition(parentDecl)
+ && parentDecl->hasModifier<ExternModifier>());
inheritanceDecl->witnessTable = witnessTable;
}