summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-20 13:33:13 -0700
committerGitHub <noreply@github.com>2024-03-20 13:33:13 -0700
commitc28a22fb8b505ff48ca0814ca290ee4f698aa38b (patch)
tree30cf242ae893c6dee3a3fdd3cf6228ffb01e2029
parent04ffa84c95b68ae50c25d32703fa9e6d49d2a10a (diff)
Fix namespace parsing. (#3803)
* Fix namespace parsing. * Fix.
-rw-r--r--source/slang/slang-parser.cpp16
-rw-r--r--tests/bugs/gh-3802.slang11
2 files changed, 17 insertions, 10 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index e1dce5731..ab69b66d8 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -3457,22 +3457,18 @@ namespace Slang
namespaceDecl = parser->astBuilder->create<NamespaceDecl>();
namespaceDecl->nameAndLoc = nameAndLoc;
namespaceDecl->loc = nameAndLoc.loc;
+ AddMember(parentDecl, namespaceDecl);
+ if (auto parentNamespace = as<NamespaceDecl>(parentDecl))
+ {
+ parser->PushScope(parentDecl);
+ nestedNamespaceDecls.add(parentNamespace);
+ }
}
}
if (!result)
{
result = namespaceDecl;
}
- else if (parentDecl)
- {
- if (auto parentNamespace = as<NamespaceDecl>(parentDecl))
- {
- parser->PushScope(parentDecl);
- nestedNamespaceDecls.add(parentNamespace);
- }
- AddMember(parentDecl, namespaceDecl);
- }
-
parentDecl = namespaceDecl;
} while (AdvanceIf(parser, TokenType::Dot) || AdvanceIf(parser, TokenType::Scope));
diff --git a/tests/bugs/gh-3802.slang b/tests/bugs/gh-3802.slang
new file mode 100644
index 000000000..7b09592f3
--- /dev/null
+++ b/tests/bugs/gh-3802.slang
@@ -0,0 +1,11 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly
+
+namespace foo::bar::baz {}
+namespace foo::bar {} // <- leaving this out "fixes" the issue
+
+// CHECK: OpEntryPoint
+
+[shader("compute")]
+[numthreads(1, 1, 1)]
+void computeMain()
+{} \ No newline at end of file