Skip to content

Commit 525412c

Browse files
Report error on nested functions. (#5792)
* Report error on nested functions. * Fix. --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
1 parent 2bec21e commit 525412c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

source/slang/slang-parser.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -5783,6 +5783,27 @@ DeclStmt* Parser::parseVarDeclrStatement(Modifiers modifiers)
57835783
FillPosition(varDeclrStatement);
57845784
auto decl = ParseDeclWithModifiers(this, currentScope->containerDecl, modifiers);
57855785
varDeclrStatement->decl = decl;
5786+
5787+
if (as<VarDeclBase>(decl))
5788+
{
5789+
}
5790+
else if (as<DeclGroup>(decl))
5791+
{
5792+
}
5793+
else if (as<AggTypeDecl>(decl))
5794+
{
5795+
}
5796+
else if (as<TypeDefDecl>(decl))
5797+
{
5798+
}
5799+
else if (as<UsingDecl>(decl))
5800+
{
5801+
}
5802+
else
5803+
{
5804+
sink->diagnose(decl->loc, Diagnostics::declNotAllowed, decl->astNodeType);
5805+
}
5806+
57865807
return varDeclrStatement;
57875808
}
57885809

tests/diagnostics/nested-func.slang

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
2+
3+
4+
struct VertexOutput{float Input;}
5+
float4 fragmentMain(VertexOutput vertex) : SV_Target
6+
{
7+
// CHECK: ([[# @LINE+1]]): error 30102
8+
static float GetValue(int val) { return vertex.Input; } // Simplified example
9+
float a = GetValue(vertex.Input);
10+
11+
// etc
12+
}

tests/diagnostics/uninitialized-local-variables.slang

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//TEST:SIMPLE(filecheck=CHK): -target spirv
22

3+
float f(float) { return 1; }
4+
35
// Should not warn here (unconditionalBranch)
46
float3 unconditional(int mode)
57
{
6-
float f(float) { return 1; }
7-
88
float k0;
99
float k1;
1010

0 commit comments

Comments
 (0)