Skip to content

Commit

Permalink
Compiler: Fix AccessIndex validation with a struct with disabled members
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Oct 15, 2023
1 parent 19a610b commit 163e0ed
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/NZSL/Ast/SanitizeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4236,7 +4236,31 @@ namespace nzsl::Ast
std::size_t structIndex = ResolveStructIndex(resolvedExprType, indexExpr->sourceLocation);
const StructDescription* s = m_context->structs.Retrieve(structIndex, indexExpr->sourceLocation);

std::optional<ExpressionType> resolvedFieldTypeOpt = ResolveTypeExpr(s->members[fieldIndex].type, true, indexExpr->sourceLocation);
// We can't manually index field using fieldIndex because some fields may be disabled
const StructDescription::StructMember* fieldPtr = nullptr;
for (const auto& field : s->members)
{
if (field.cond.HasValue())
{
if (field.cond.IsResultingValue())
{
if (!field.cond.GetResultingValue())
continue;
}
else
return ValidationResult::Unresolved;
}

if (fieldIndex == 0)
{
fieldPtr = &field;
break;
}

fieldIndex--;
}

std::optional<ExpressionType> resolvedFieldTypeOpt = ResolveTypeExpr(fieldPtr->type, true, indexExpr->sourceLocation);
if (!resolvedFieldTypeOpt.has_value())
return ValidationResult::Unresolved;

Expand Down

0 comments on commit 163e0ed

Please sign in to comment.