Skip to content

Commit

Permalink
decoder: Avoid nil induced panic when collecting targets
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Mar 29, 2023
1 parent 336139f commit 286886d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions decoder/reference_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,17 +774,19 @@ func (d *PathDecoder) collectInferredReferenceTargetsForBody(addr lang.Address,
attrExpr = attr.Expr
}

if aSchema.Constraint != nil {
ref.NestedTargets = make(reference.Targets, 0)
expr, ok := newExpression(d.pathCtx, attrExpr, aSchema.Constraint).(ReferenceTargetsExpression)
if ok {
ctx := context.Background()
ref.NestedTargets = append(ref.NestedTargets, expr.ReferenceTargets(ctx, targetCtx)...)
}
} else {
if attrExpr != nil && !attrType.IsPrimitiveType() {
if attrExpr != nil {
if aSchema.Constraint != nil {
ref.NestedTargets = make(reference.Targets, 0)
ref.NestedTargets = append(ref.NestedTargets, decodeReferenceTargetsForComplexTypeExpr(attrAddr, attrExpr, attrType, bAddrSchema.ScopeId)...)
expr, ok := newExpression(d.pathCtx, attrExpr, aSchema.Constraint).(ReferenceTargetsExpression)
if ok {
ctx := context.Background()
ref.NestedTargets = append(ref.NestedTargets, expr.ReferenceTargets(ctx, targetCtx)...)
}
} else {
if !attrType.IsPrimitiveType() {
ref.NestedTargets = make(reference.Targets, 0)
ref.NestedTargets = append(ref.NestedTargets, decodeReferenceTargetsForComplexTypeExpr(attrAddr, attrExpr, attrType, bAddrSchema.ScopeId)...)
}
}
}

Expand Down

0 comments on commit 286886d

Please sign in to comment.