Skip to content

Commit

Permalink
Check decl nesting for namespaces. (#5910)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Dec 19, 2024
1 parent abeb375 commit a805756
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 7 additions & 8 deletions source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4634,14 +4634,6 @@ static void CompleteDecl(
ContainerDecl* containerDecl,
Modifiers modifiers)
{

// If this is a namespace and already added, we don't want to add to the parent
// Or add any modifiers
if (as<NamespaceDecl>(decl) && decl->parentDecl)
{
return;
}

// Add any modifiers we parsed before the declaration to the list
// of modifiers on the declaration itself.
//
Expand Down Expand Up @@ -4699,6 +4691,13 @@ static void CompleteDecl(
}
}

// If this is a namespace and already added, we don't want to add to the parent
// Or add any modifiers
if (as<NamespaceDecl>(decl) && decl->parentDecl)
{
return;
}

if (!as<GenericDecl>(containerDecl))
{
// Make sure the decl is properly nested inside its lexical parent
Expand Down
7 changes: 7 additions & 0 deletions tests/diagnostics/invalid-namespace-nesting.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv

struct Type
{
// CHECK: ([[# @LINE+1]]): error 30102:
namespace ns {}
}

0 comments on commit a805756

Please sign in to comment.