Skip to content

Commit

Permalink
Report error on nested functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe committed Dec 6, 2024
1 parent 0d5636c commit 3e30b2b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5783,6 +5783,24 @@ DeclStmt* Parser::parseVarDeclrStatement(Modifiers modifiers)
FillPosition(varDeclrStatement);
auto decl = ParseDeclWithModifiers(this, currentScope->containerDecl, modifiers);
varDeclrStatement->decl = decl;

if (as<VarDeclBase>(decl))
{
}
else if (as<DeclGroup>(decl))
{
}
else if (as<AggTypeDecl>(decl))
{
}
else if (as<TypeDefDecl>(decl))
{
}
else
{
sink->diagnose(decl->loc, Diagnostics::declNotAllowed, decl->astNodeType);
}

return varDeclrStatement;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/diagnostics/nested-func.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):


struct VertexOutput{float Input;}
float4 fragmentMain(VertexOutput vertex) : SV_Target
{
// CHECK: ([[# @LINE+1]]): error 30102
static float GetValue(int val) { return vertex.Input; } // Simplified example
float a = GetValue(vertex.Input);

// etc
}

0 comments on commit 3e30b2b

Please sign in to comment.