Skip to content

Commit

Permalink
fix: add missing string representation for array+subscripts
Browse files Browse the repository at this point in the history
  • Loading branch information
flosch committed Feb 1, 2023
1 parent a3f9633 commit b09d398
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go test fuzz v1
string("{{complex.comments.A[\"\"]}}")
string("0")
25 changes: 17 additions & 8 deletions variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ type variablePart struct {
callingArgs []functionCallArgument // needed for a function call, represents all argument nodes (INode supports nested function calls)
}

func (p *variablePart) String() string {
switch p.typ {
case varTypeInt:
return strconv.Itoa(p.i)
case varTypeIdent:
return p.s
case varTypeSubscript:
return "[subscript]"
case varTypeArray:
return "[array]"
}

panic("unimplemented")
}

type functionCallArgument interface {
Evaluate(*ExecutionContext) (*Value, *Error)
}
Expand Down Expand Up @@ -220,15 +235,9 @@ func (vr *variableResolver) FilterApplied(name string) bool {
func (vr *variableResolver) String() string {
parts := make([]string, 0, len(vr.parts))
for _, p := range vr.parts {
switch p.typ {
case varTypeInt:
parts = append(parts, strconv.Itoa(p.i))
case varTypeIdent:
parts = append(parts, p.s)
default:
panic("unimplemented")
}
parts = append(parts, p.String())
}

return strings.Join(parts, ".")
}

Expand Down

0 comments on commit b09d398

Please sign in to comment.