summaryrefslogtreecommitdiffstats
path: root/source/slang/check.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2019-02-05 19:41:33 -0800
committerGitHub <noreply@github.com>2019-02-05 19:41:33 -0800
commit2d1291ae4f3de66e2d958b148d0811cbf2ee9c60 (patch)
treea81b861c6cbd345e323a1f5ee3bc4eec61646b96 /source/slang/check.cpp
parent3d62beab61490ce3e7ed60b48fd6a11c8eeb44ad (diff)
parentc6870dcbf6f720bfbfe7e38f7d9625d69bedde3d (diff)
Merge pull request #829 from tfoleyNV/fix-nested-type-conformances
Fix checking of interface conformances for nested types
Diffstat (limited to 'source/slang/check.cpp')
-rw-r--r--source/slang/check.cpp52
1 files changed, 40 insertions, 12 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index c3f10fb4c..cce6a545a 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -2883,6 +2883,45 @@ namespace Slang
syntaxNode->modifiers.first = resultModifiers;
}
+ /// Perform checking of interface conformaces for this decl and all its children
+ void checkInterfaceConformancesRec(Decl* decl)
+ {
+ // Any user-defined type may have declared interface conformances,
+ // which we should check.
+ //
+ if( auto aggTypeDecl = as<AggTypeDecl>(decl) )
+ {
+ checkAggTypeConformance(aggTypeDecl);
+ }
+ // Conformances can also come via `extension` declarations, and
+ // we should check them against the type(s) being extended.
+ //
+ else if(auto extensionDecl = as<ExtensionDecl>(decl))
+ {
+ checkExtensionConformance(extensionDecl);
+ }
+
+ // We need to handle the recursive cases here, the first
+ // of which is a generic decl, where we want to recurivsely
+ // check the inner declaration.
+ //
+ if(auto genericDecl = as<GenericDecl>(decl))
+ {
+ checkInterfaceConformancesRec(genericDecl->inner);
+ }
+ // For any other kind of container declaration, we will
+ // recurse into all of its member declarations, so that
+ // we can handle, e.g., nested `struct` types.
+ //
+ else if(auto containerDecl = as<ContainerDecl>(decl))
+ {
+ for(auto member : containerDecl->Members)
+ {
+ checkInterfaceConformancesRec(member);
+ }
+ }
+ }
+
void visitModuleDecl(ModuleDecl* programNode)
{
// Try to register all the builtin decls
@@ -2988,18 +3027,7 @@ namespace Slang
if (pass == 0)
{
- // now we can check all interface conformances
- for (auto & s : programNode->getMembersOfType<AggTypeDecl>())
- checkAggTypeConformance(s);
- for (auto & s : programNode->getMembersOfType<ExtensionDecl>())
- checkExtensionConformance(s);
- for (auto & g : programNode->getMembersOfType<GenericDecl>())
- {
- if (auto innerAggDecl = as<AggTypeDecl>(g->inner))
- checkAggTypeConformance(innerAggDecl);
- else if (auto innerExtDecl = as<ExtensionDecl>(g->inner))
- checkExtensionConformance(innerExtDecl);
- }
+ checkInterfaceConformancesRec(programNode);
}
}
}