diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 8c5d8e9b4c..eeb1b2015b 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -2575,16 +2575,22 @@ namespace Slang return generatedCtor; } + /// TODO: cache result bool _structHasMemberWithValue(ASTBuilder* m_astBuilder, StructDecl* structDecl) { if (getMembersOfType(m_astBuilder, structDecl, MemberFilterStyle::Instance).getFirstOrNull()) return true; - for (auto i : getMembersOfType(m_astBuilder, structDecl, MemberFilterStyle::Instance)) + for (auto inheritanceMember : getMembersOfType(m_astBuilder, structDecl, MemberFilterStyle::Instance)) { - if (auto memberStruct = as(i.getDecl()->base.type)) - if (_structHasMemberWithValue(m_astBuilder, memberStruct)) - return true; + auto declRefType = as(inheritanceMember.getDecl()->base.type); + if (!declRefType) + continue; + auto baseStruct = as(declRefType->getDeclRef().getDecl()); + if (!baseStruct) + continue; + if (_structHasMemberWithValue(m_astBuilder, baseStruct)) + return true; } return false; } @@ -2610,9 +2616,10 @@ namespace Slang if (auto structDecl = as(aggTypeDecl)) { // First part of auto-generating constructors/functions is inside `SemanticsDeclConformancesVisitor::visitAggTypeDecl` - // * Create declarations for constructors/functions. + // * Create declarations for constructors/functions. This is important so Slang may use the declarations before + // we have the chance to synthisize function bodies // Second part of auto-generating constructors/functions is inside `SemanticsDeclBodyVisitor::visitAggTypeDecl` - // * Add bodies to our declarations + // * Add bodies to our declarations. // // These are split up so we can assign declarations before we finish definitions // @@ -2660,6 +2667,7 @@ namespace Slang structDecl->addMember(zeroInitFunc); } + if (_structHasMemberWithValue(getASTBuilder(), structDecl)) { // 2. Add an declaration for default-ctor if missing a real default-ctor. @@ -8094,9 +8102,10 @@ namespace Slang return; // First part of auto-generating constructors/functions is inside `SemanticsDeclConformancesVisitor::visitAggTypeDecl` - // * Create declarations for constructors/functions. + // * Create declarations for constructors/functions. This is important so Slang may use the declarations before + // we have the chance to synthisize function bodies // Second part of auto-generating constructors/functions is inside `SemanticsDeclBodyVisitor::visitAggTypeDecl` - // * Add bodies to our declarations + // * Add bodies to our declarations. // // These are split up so we can assign declarations before we finish definitions //