Skip to content

Commit

Permalink
Report error on nested functions. (shader-slang#5792)
Browse files Browse the repository at this point in the history
* Report error on nested functions.

* Fix.

---------

Co-authored-by: Ellie Hermaszewska <[email protected]>
  • Loading branch information
csyonghe and expipiplus1 authored Dec 9, 2024
1 parent 2bec21e commit 525412c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
21 changes: 21 additions & 0 deletions source/slang/slang-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5783,6 +5783,27 @@ 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 if (as<UsingDecl>(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
}
4 changes: 2 additions & 2 deletions tests/diagnostics/uninitialized-local-variables.slang
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//TEST:SIMPLE(filecheck=CHK): -target spirv

float f(float) { return 1; }

// Should not warn here (unconditionalBranch)
float3 unconditional(int mode)
{
float f(float) { return 1; }

float k0;
float k1;

Expand Down

0 comments on commit 525412c

Please sign in to comment.