summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-27 13:03:28 -0700
committerGitHub <noreply@github.com>2024-03-27 13:03:28 -0700
commitb346a9333ae6d09f053db60b3006e6e074332ac2 (patch)
treeddbbd33bb93fb858deb8c2c94b8905d8e2c562ea
parent8395acfa0ad8379011e4470b94362189cafac93f (diff)
Allow var/param names to be the same as type name. (#3850)
-rw-r--r--source/slang/slang-check-decl.cpp12
-rw-r--r--tests/bugs/gh-3824.slang20
2 files changed, 28 insertions, 4 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index ed97e412d..78eccbc8c 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -1547,7 +1547,8 @@ namespace Slang
}
else
{
- initExpr = CheckExpr(initExpr);
+ SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(varDecl));
+ initExpr = subVisitor.CheckExpr(initExpr);
// TODO: We might need some additional steps here to ensure
// that the type of the expression is one we are okay with
@@ -1568,7 +1569,8 @@ namespace Slang
{
// A variable with an explicit type is simpler, for the
// most part.
- TypeExp typeExp = CheckUsableType(varDecl->type);
+ SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(varDecl));
+ TypeExp typeExp = subVisitor.CheckUsableType(varDecl->type);
varDecl->type = typeExp;
if (varDecl->type.equals(m_astBuilder->getVoidType()))
{
@@ -6998,7 +7000,8 @@ namespace Slang
auto typeExpr = paramDecl->type;
if(typeExpr.exp)
{
- typeExpr = CheckUsableType(typeExpr);
+ SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(paramDecl));
+ typeExpr = subVisitor.CheckUsableType(typeExpr);
paramDecl->type = typeExpr;
checkMeshOutputDecl(paramDecl);
}
@@ -7640,7 +7643,8 @@ namespace Slang
void SemanticsDeclHeaderVisitor::visitPropertyDecl(PropertyDecl* decl)
{
- decl->type = CheckUsableType(decl->type);
+ SemanticsVisitor subVisitor(withDeclToExcludeFromLookup(decl));
+ decl->type = subVisitor.CheckUsableType(decl->type);
visitAbstractStorageDeclCommon(decl);
checkVisibility(decl);
}
diff --git a/tests/bugs/gh-3824.slang b/tests/bugs/gh-3824.slang
new file mode 100644
index 000000000..1d2d3685f
--- /dev/null
+++ b/tests/bugs/gh-3824.slang
@@ -0,0 +1,20 @@
+//TEST:SIMPLE(filecheck=CHECK):-target spirv -emit-spirv-directly
+
+// CHECK: OpEntryPoint
+
+namespace example {
+ struct Example {}
+}
+
+struct Struct {
+ example::Example example;
+}
+
+void func(Struct Struct)
+{
+ // Test parameter name to be the same as type name.
+}
+
+[numthreads(1,1,1)]
+void main()
+{} \ No newline at end of file