diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2019-10-10 11:55:52 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-10-10 11:57:33 +0200 |
| commit | a4efa8c091bb41968c2a2e198fa239625ed8a24e (patch) | |
| tree | 902e952ce0abf2eb06d757f9587497e14ef29a56 /pkg/compiler | |
| parent | d52eff2843084b3aeada4e46029519cf17067385 (diff) | |
pkg/compiler: fix infinite recursion in template instantiation
Currently we replace a template argument and then recurse
into the new type AST to see if there is more to replace.
If the description is buggy and the template argument
contains itself, then we will recurse infintiely trying
to replace it more and more.
Use post-order traversal when replacing template argument to fix this.
Diffstat (limited to 'pkg/compiler')
| -rw-r--r-- | pkg/compiler/check.go | 2 | ||||
| -rw-r--r-- | pkg/compiler/compiler_test.go | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index eb57228ca..adf6f4e9d 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -942,7 +942,7 @@ func (comp *compiler) instantiate(templ ast.Node, params []*ast.Ident, args []*a } argUsed := make(map[string]bool) err0 := comp.errors - templ.Walk(ast.Recursive(func(n ast.Node) { + templ.Walk(ast.PostRecursive(func(n ast.Node) { templArg, ok := n.(*ast.Type) if !ok { return diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 8f10ac586..4ea5b2721 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -201,6 +201,11 @@ l t type D[e]l`, "E", "#", + ` +type p b[L] +type b[L] { + e b[L[L]] +}`, } { Fuzz([]byte(data)[:len(data):len(data)]) } |
