summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
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