diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2025-05-30 14:54:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-30 21:54:31 +0000 |
| commit | 3ca27faa23a92124f26875a6f00bcfc3a1c6431e (patch) | |
| tree | a2fad6f0e0bbf99a574a5a6d0348970dcd16ddf2 | |
| parent | b16eb592cc31b7cc9ba3d2f9525486c282996a9e (diff) | |
Ensure we do not have an `initExpr` on a `VarDecl` inside an `InterfaceDecl` (#7283)
* Ensure we do not have an initExpr on a var inside an InterfaceDecl
Ensure we do not have an initExpr on a var inside an InterfaceDecl. If we do, send an error.
Ensure the language server does not segfault with this error as per the issue.
* format code
* split tests
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 11 | ||||
| -rw-r--r-- | tests/bugs/static-const-init-expr-with-interface-1.slang | 15 | ||||
| -rw-r--r-- | tests/bugs/static-const-init-expr-with-interface-2.slang | 15 |
3 files changed, 41 insertions, 0 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 71aa71e69..cc65edd2f 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -2464,6 +2464,17 @@ bool DiagnoseIsAllowedInitExpr(VarDeclBase* varDecl, DiagnosticSink* sink) return false; } + if (as<InterfaceDecl>(varDecl->parentDecl)) + { + if (sink && varDecl->initExpr) + sink->diagnose( + varDecl, + Diagnostics::cannotHaveInitializer, + varDecl, + "an interface requirement"); + return false; + } + return true; } diff --git a/tests/bugs/static-const-init-expr-with-interface-1.slang b/tests/bugs/static-const-init-expr-with-interface-1.slang new file mode 100644 index 000000000..bab63c167 --- /dev/null +++ b/tests/bugs/static-const-init-expr-with-interface-1.slang @@ -0,0 +1,15 @@ +//TEST:LANG_SERVER(filecheck=CHECK): + +//HOVER:7,25 +//CHECK:Bug.badVar = 0 +interface Bug +{ + static const int badVar = 0; +} + +RWStructuredBuffer<int> b; +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + b[0] = Bug::badVar; +} diff --git a/tests/bugs/static-const-init-expr-with-interface-2.slang b/tests/bugs/static-const-init-expr-with-interface-2.slang new file mode 100644 index 000000000..6976f1303 --- /dev/null +++ b/tests/bugs/static-const-init-expr-with-interface-2.slang @@ -0,0 +1,15 @@ +//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target spirv + +//CHECK: error 30623 + +interface Bug +{ + static const int badVar = 0; +} + +RWStructuredBuffer<int> b; +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + b[0] = Bug::badVar; +} |
