Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report error on nested functions. #5792

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
{
}
Comment on lines +5787 to +5801
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a weird way of avoiding ||?

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
Loading