From 525412c67ceea9f52a26e42044e99b349ebc2535 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 9 Dec 2024 04:47:16 -0800 Subject: Report error on nested functions. (#5792) * Report error on nested functions. * Fix. --------- Co-authored-by: Ellie Hermaszewska --- source/slang/slang-parser.cpp | 21 +++++++++++++++++++++ tests/diagnostics/nested-func.slang | 12 ++++++++++++ .../diagnostics/uninitialized-local-variables.slang | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/diagnostics/nested-func.slang diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 8fb3be39c..172e3130f 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -5783,6 +5783,27 @@ DeclStmt* Parser::parseVarDeclrStatement(Modifiers modifiers) FillPosition(varDeclrStatement); auto decl = ParseDeclWithModifiers(this, currentScope->containerDecl, modifiers); varDeclrStatement->decl = decl; + + if (as(decl)) + { + } + else if (as(decl)) + { + } + else if (as(decl)) + { + } + else if (as(decl)) + { + } + else if (as(decl)) + { + } + else + { + sink->diagnose(decl->loc, Diagnostics::declNotAllowed, decl->astNodeType); + } + return varDeclrStatement; } diff --git a/tests/diagnostics/nested-func.slang b/tests/diagnostics/nested-func.slang new file mode 100644 index 000000000..42634cb8a --- /dev/null +++ b/tests/diagnostics/nested-func.slang @@ -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 +} diff --git a/tests/diagnostics/uninitialized-local-variables.slang b/tests/diagnostics/uninitialized-local-variables.slang index 3c3dba881..d8cea8a65 100644 --- a/tests/diagnostics/uninitialized-local-variables.slang +++ b/tests/diagnostics/uninitialized-local-variables.slang @@ -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; -- cgit v1.2.3