Skip to content

Commit

Permalink
Fix a crash caused when trying to concatenate a pattern fragment with…
Browse files Browse the repository at this point in the history
… something else.
  • Loading branch information
jaqx0r committed Dec 17, 2019
1 parent 2d5ca6b commit de286b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/vm/checker/checker.go
Expand Up @@ -678,10 +678,15 @@ func (p *patternEvaluator) VisitBefore(n ast.Node) (ast.Visitor, ast.Node) {
if v.Symbol == nil {
return nil, n
}
idPattern := v.Symbol.Binding.(*ast.PatternFragment).Pattern
pf, ok := v.Symbol.Binding.(*ast.PatternFragment)
if !ok {
p.errors.Add(v.Pos(), fmt.Sprintf("Can't append %s `%s' to this pattern.\n\tTry using a `const'-defined pattern fragment.", v.Symbol.Kind, v.Symbol.Name))
return nil, n
}
idPattern := pf.Pattern
if idPattern == "" {
idEvaluator := &patternEvaluator{scope: p.scope}
_ = ast.Walk(idEvaluator, v.Symbol.Binding.(*ast.PatternFragment))
_ = ast.Walk(idEvaluator, pf)
idPattern = idEvaluator.pattern.String()
}
p.pattern.WriteString(idPattern)
Expand Down
6 changes: 6 additions & 0 deletions internal/vm/checker/checker_test.go
Expand Up @@ -189,6 +189,12 @@ next
del $0
}`,
[]string{"delete incorrect object:3:7: Cannot delete this.", "\tTry deleting from a dimensioned metric with this as an index."}},

{"pattern fragment plus anything",
`gauge e
// + e
`,
[]string{"pattern fragment plus anything:2:6: Can't append variable `e' to this pattern.", "\tTry using a `const'-defined pattern fragment."}},
}

func TestCheckInvalidPrograms(t *testing.T) {
Expand Down

0 comments on commit de286b1

Please sign in to comment.