summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-ast-modifier.h3
-rw-r--r--source/slang/slang-check-decl.cpp10
-rw-r--r--source/slang/slang-lookup.cpp8
-rw-r--r--tests/language-feature/enums/explicit-tag-type.slang33
-rw-r--r--tests/language-feature/enums/explicit-tag-type.slang.expected.txt4
5 files changed, 58 insertions, 0 deletions
diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h
index c986186fd..eb30e880e 100644
--- a/source/slang/slang-ast-modifier.h
+++ b/source/slang/slang-ast-modifier.h
@@ -29,6 +29,9 @@ class ExportedModifier : public Modifier { SLANG_CLASS(ExportedModifier)};
class ConstExprModifier : public Modifier { SLANG_CLASS(ConstExprModifier)};
class GloballyCoherentModifier : public Modifier { SLANG_CLASS(GloballyCoherentModifier)};
+ /// A modifier that indicates an `InheritanceDecl` should be ignored during name lookup (and related checks).
+class IgnoreForLookupModifier : public Modifier { SLANG_CLASS(IgnoreForLookupModifier) };
+
// A modifier that marks something as an operation that
// has a one-to-one translation to the IR, and thus
// has no direct definition in the high-level language.
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 9c8f022ae..f965f9759 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -2985,6 +2985,16 @@ namespace Slang
// For now we will just be harsh and require it
// to be one of a few builtin types.
validateEnumTagType(tagType, tagTypeInheritanceDecl->loc);
+
+ // Note: The `InheritanceDecl` that introduces a tag
+ // type isn't actually representing a super-type of
+ // the `enum`, and things like name lookup need to
+ // know to ignore that "inheritance" relationship.
+ //
+ // We add a modifier to the `InheritanceDecl` to ensure
+ // that it can be detected and ignored by such steps.
+ //
+ addModifier(tagTypeInheritanceDecl, m_astBuilder->create<IgnoreForLookupModifier>());
}
decl->tagType = tagType;
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp
index 01451470e..c9b922415 100644
--- a/source/slang/slang-lookup.cpp
+++ b/source/slang/slang-lookup.cpp
@@ -528,6 +528,14 @@ static void _lookUpMembersInSuperTypeDeclImpl(
{
ensureDecl(semantics, inheritanceDeclRef.getDecl(), DeclCheckState::CanUseBaseOfInheritanceDecl);
+ // Some things that are syntactically `InheritanceDecl`s don't actually
+ // represent a subtype/supertype relationship, and thus we shouldn't
+ // include members from the base type when doing lookup in the
+ // derived type.
+ //
+ if(inheritanceDeclRef.getDecl()->hasModifier<IgnoreForLookupModifier>())
+ continue;
+
auto baseType = getSup(astBuilder, inheritanceDeclRef);
if( auto baseDeclRefType = as<DeclRefType>(baseType) )
{
diff --git a/tests/language-feature/enums/explicit-tag-type.slang b/tests/language-feature/enums/explicit-tag-type.slang
new file mode 100644
index 000000000..b55266fcb
--- /dev/null
+++ b/tests/language-feature/enums/explicit-tag-type.slang
@@ -0,0 +1,33 @@
+// explicit-tag-type.slang
+
+// Test that the underlying "tag type" of an `enum` can be set.
+
+//TEST(compute):COMPARE_COMPUTE:
+
+enum Channel : uint
+{
+ Red,
+ Green,
+ Blue,
+ Alpha,
+}
+
+uint test(uint val)
+{
+ Channel channel = Channel(val);
+ uint u = uint(channel) + 1;
+ channel = Channel(u & 0x3);
+ return uint(channel);
+}
+
+//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/explicit-tag-type.slang.expected.txt b/tests/language-feature/enums/explicit-tag-type.slang.expected.txt
new file mode 100644
index 000000000..82b6055c7
--- /dev/null
+++ b/tests/language-feature/enums/explicit-tag-type.slang.expected.txt
@@ -0,0 +1,4 @@
+1
+2
+3
+0