summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorMukund Keshava <mkeshava@nvidia.com>2025-05-27 20:24:15 +0530
committerGitHub <noreply@github.com>2025-05-27 14:54:15 +0000
commit9ef7072397457e8cdb8a63a1a6953d01f46b2904 (patch)
treee0745658201dd89f36d033f96c8a27798f462bbd /source
parentf570e109c4039e15526af38e17f350c115327489 (diff)
Add check for subscript operator return type (#7244)
Fixes #6987
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-decl.cpp11
-rw-r--r--source/slang/slang-diagnostic-defs.h5
2 files changed, 15 insertions, 1 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 7a0dcb06f..f8a80c09b 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -10405,7 +10405,16 @@ void SemanticsDeclHeaderVisitor::visitAbstractStorageDeclCommon(ContainerDecl* d
void SemanticsDeclHeaderVisitor::visitSubscriptDecl(SubscriptDecl* decl)
{
- decl->returnType = CheckUsableType(decl->returnType, decl);
+ // __subscript needs to have a return type specified. Check if return type
+ // is missing (represented as IncompleteExpr) and return an error.
+ if (decl->returnType.exp && as<IncompleteExpr>(decl->returnType.exp))
+ {
+ getSink()->diagnose(decl, Diagnostics::subscriptMustHaveReturnType);
+ }
+ else if (decl->returnType.exp)
+ {
+ decl->returnType = CheckUsableType(decl->returnType, decl);
+ }
visitAbstractStorageDeclCommon(decl);
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 3babc9a56..0814bb2a0 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -1710,6 +1710,11 @@ DIAGNOSTIC(
Error,
multiDimensionalArrayNotSupported,
"multi-dimensional array is not supported.")
+DIAGNOSTIC(
+ 30901,
+ Error,
+ subscriptMustHaveReturnType,
+ "__subscript declaration must have a return type specified after '->'")
// 310xx: properties
// 311xx: accessors