summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-check-conformance.cpp14
-rw-r--r--source/slang/slang-syntax.h5
-rw-r--r--tests/language-feature/enums/enum-tag-type-compare.slang47
-rw-r--r--tests/language-feature/enums/enum-tag-type-compare.slang.expected.txt4
4 files changed, 69 insertions, 1 deletions
diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp
index 174d4be89..b95df520d 100644
--- a/source/slang/slang-check-conformance.cpp
+++ b/source/slang/slang-check-conformance.cpp
@@ -211,6 +211,20 @@ namespace Slang
auto inheritedType = getBaseType(m_astBuilder, inheritanceDeclRef);
+
+ // There's one annoying corner case where something that *looks* like an inheritnace
+ // declaration isn't actually one, and that is when an `enum` type includes an explicit
+ // declaration of its "tag type."
+ //
+ if (auto enumDeclRef = declRef.as<EnumDecl>())
+ {
+ if (inheritedType->equals(getTagType(m_astBuilder, enumDeclRef)))
+ {
+ return;
+ }
+ }
+
+
// We need to ensure that the witness that gets created
// is a composite one, reflecting lookup through
// the inheritance declaration.
diff --git a/source/slang/slang-syntax.h b/source/slang/slang-syntax.h
index 9589f00fd..a23ad224e 100644
--- a/source/slang/slang-syntax.h
+++ b/source/slang/slang-syntax.h
@@ -136,7 +136,10 @@ namespace Slang
return getMembersOfType<VarDecl>(declRef, filterStyle);
}
-
+ inline Type* getTagType(ASTBuilder* astBuilder, DeclRef<EnumDecl> const& declRef)
+ {
+ return declRef.substitute(astBuilder, declRef.getDecl()->tagType);
+ }
inline Type* getBaseType(ASTBuilder* astBuilder, DeclRef<InheritanceDecl> const& declRef)
{
diff --git a/tests/language-feature/enums/enum-tag-type-compare.slang b/tests/language-feature/enums/enum-tag-type-compare.slang
new file mode 100644
index 000000000..ce88860ee
--- /dev/null
+++ b/tests/language-feature/enums/enum-tag-type-compare.slang
@@ -0,0 +1,47 @@
+// enum-tag-type-compare.slang
+
+// Test comparisons for `enum`s with explicit tag types
+
+//TEST(compute):COMPARE_COMPUTE:
+
+enum class MaterialType : uint32_t
+{
+ A,
+ B,
+ C,
+ D,
+}
+
+struct Material
+{
+ MaterialType getType() { return MaterialType(_type); }
+
+ uint _type;
+}
+
+uint test(uint val)
+{
+ Material m = { val };
+
+ MaterialType b = MaterialType.B;
+
+ int result = 0x100000;
+ if(m.getType() == b) result += 0x10;
+ if(m.getType() != b) result += 0x100;
+ if((uint)m.getType() == (uint)b) result += 0x1000;
+ if((uint)m.getType() != (uint)b) result += 0x10000;
+
+ return result;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ uint inVal = tid;
+ uint outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/enums/enum-tag-type-compare.slang.expected.txt b/tests/language-feature/enums/enum-tag-type-compare.slang.expected.txt
new file mode 100644
index 000000000..2d91bbbdd
--- /dev/null
+++ b/tests/language-feature/enums/enum-tag-type-compare.slang.expected.txt
@@ -0,0 +1,4 @@
+110100
+101010
+110100
+110100