summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-inheritance.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-21 15:45:27 -0700
committerGitHub <noreply@github.com>2024-03-21 15:45:27 -0700
commitdd32414bd7332c55dc37ea2972ffcca73328d834 (patch)
tree7bcca5ab90c794bb0caaad1b78b08dfa16240d5a /source/slang/slang-check-inheritance.cpp
parent9bd6b233b38f8ae0de72f41939be0cb2879b9919 (diff)
Diagnose cyclic references in inheritance graph. (#3811)
Diffstat (limited to 'source/slang/slang-check-inheritance.cpp')
-rw-r--r--source/slang/slang-check-inheritance.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/slang/slang-check-inheritance.cpp b/source/slang/slang-check-inheritance.cpp
index 5fff47cf1..18624424c 100644
--- a/source/slang/slang-check-inheritance.cpp
+++ b/source/slang/slang-check-inheritance.cpp
@@ -569,6 +569,18 @@ namespace Slang
// later.
}
+ // If we still cannot find a facet, then there is a true cycle in
+ // the inheritance graph, which is an error in the user code.
+ if (!foundFacet.getImpl())
+ {
+ if (!bases.isEmpty())
+ {
+ auto baseDecl = (*bases.begin())->facetImpl.origin.declRef.getDecl();
+ getSink()->diagnose(baseDecl, Diagnostics::cyclicReferenceInInheritance, baseDecl);
+ }
+ return;
+ }
+
// At this point we definitely have a facet we'd like to
// add to the output, whether it was found via the true
// C3 approach, or our relaxed rule above.
@@ -793,6 +805,8 @@ namespace Slang
{
for (auto base : *this)
{
+ if (base->facets.isEmpty())
+ continue;
if (base->facets.getTail().containsMatchFor(facet))
return true;
}