summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-diagnostic-defs.h3
-rw-r--r--source/slang/slang-parser.cpp39
-rw-r--r--tests/diagnostics/class-keyword.slang10
-rw-r--r--tests/diagnostics/class-keyword.slang.expected8
4 files changed, 56 insertions, 4 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index e23d88fa4..559323696 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -227,6 +227,9 @@ DIAGNOSTIC(20008, Error, invalidOperator, "invalid operator '$0'.")
DIAGNOSTIC(20011, Error, unexpectedColon, "unexpected ':'.")
DIAGNOSTIC(20012, Error, invalidSPIRVVersion, "Expecting SPIR-V version as either 'major.minor', or quoted if has patch (eg for SPIR-V 1.2, '1.2' or \"1.2\"')")
DIAGNOSTIC(20013, Error, invalidCUDASMVersion, "Expecting CUDA SM version as either 'major.minor', or quoted if has patch (eg for '7.0' or \"7.0\"')")
+
+DIAGNOSTIC(20014, Error, classIsReservedKeyword, "'class' is a reserved keyword in this context; use 'struct' instead.")
+
//
// 3xxxx - Semantic analysis
//
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 40bb91d77..466feecf1 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -2179,10 +2179,36 @@ namespace Slang
}
else if( parser->LookAheadToken("class") )
{
- auto decl = parser->ParseClass();
- typeSpec.decl = decl;
- typeSpec.expr = createDeclRefType(parser, decl);
- return typeSpec;
+ // TODO(JS): Class type doesn't currently have the correct semantics. This is covered here
+ // https://github.com/shader-slang/slang/issues/2206
+ //
+ // For now the use of `class` is disabled.
+ // The remaining code around `class` left intact as likely will be the basis for the future
+ // implementation.
+
+ const bool disableClass = true;
+
+ if (disableClass)
+ {
+ parser->sink->diagnose(parser->tokenReader.peekLoc(), Diagnostics::classIsReservedKeyword);
+
+ // Consume `class`
+ advanceToken(parser);
+
+ // Indicate in recovering state.
+ parser->isRecovering = true;
+
+ // Check to confirm the result is invalid
+ SLANG_ASSERT(typeSpec.decl == nullptr && typeSpec.expr == nullptr);
+ return typeSpec;
+ }
+ else
+ {
+ auto decl = parser->ParseClass();
+ typeSpec.decl = decl;
+ typeSpec.expr = createDeclRefType(parser, decl);
+ return typeSpec;
+ }
}
else if(parser->LookAheadToken("enum"))
{
@@ -2293,6 +2319,11 @@ namespace Slang
Modifiers modifiers = inModifiers;
auto typeSpec = _parseTypeSpec(parser, modifiers);
+ if (typeSpec.expr == nullptr && typeSpec.decl == nullptr)
+ {
+ return nullptr;
+ }
+
// We may need to build up multiple declarations in a group,
// but the common case will be when we have just a single
// declaration
diff --git a/tests/diagnostics/class-keyword.slang b/tests/diagnostics/class-keyword.slang
new file mode 100644
index 000000000..c0495a614
--- /dev/null
+++ b/tests/diagnostics/class-keyword.slang
@@ -0,0 +1,10 @@
+//DIAGNOSTIC_TEST:SIMPLE:
+
+// `class` keyword is a reserved keyword in this context, and wso should produce an error.
+// It can be used in the form of `enum class`
+
+class SomeClass
+{
+ int a;
+ int b;
+};
diff --git a/tests/diagnostics/class-keyword.slang.expected b/tests/diagnostics/class-keyword.slang.expected
new file mode 100644
index 000000000..9a3a07a63
--- /dev/null
+++ b/tests/diagnostics/class-keyword.slang.expected
@@ -0,0 +1,8 @@
+result code = -1
+standard error = {
+tests/diagnostics/class-keyword.slang(6): error 20014: 'class' is a reserved keyword in this context; use 'struct' instead.
+class SomeClass
+^~~~~
+}
+standard output = {
+}