From 497033d937792e0008d70dfba3676de06ef9eb15 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:09:03 -0500 Subject: Fix issue that struct with member is not its Differential type (#7434) Close #6176. If the struct has a `no_diff` member, it should not be its Differential type. We miss this check. --- source/slang/slang-check-expr.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 43987132e..9f5c1dc2e 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1293,15 +1293,17 @@ Type* SemanticsVisitor::tryGetDifferentialType(ASTBuilder* builder, Type* type) bool SemanticsVisitor::canStructBeUsedAsSelfDifferentialType(AggTypeDecl* aggTypeDecl) { - // A struct can be used as its own differential type if all its members are differentiable - // and their differential types are the same as the original types. + // A struct can be used as its own differential type if all its members are differentiable, and + // none of the member is decorated with "no_diff", and their differential types are the same as + // the original types. // bool canBeUsed = true; for (auto varDecl : aggTypeDecl->getDirectMemberDeclsOfType()) { // Try to get the differential type of the member. Type* diffType = tryGetDifferentialType(getASTBuilder(), varDecl->getType()); - if (!diffType || !diffType->equals(varDecl->getType())) + if (!diffType || !diffType->equals(varDecl->getType()) || + varDecl->findModifier()) { canBeUsed = false; break; -- cgit v1.2.3