aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Chaignon <paul.chaignon@orange.com>2019-10-23 09:27:03 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-10-23 10:22:35 +0200
commitd3cea9507fca333c23ebf5b19bfddc6ff17a9181 (patch)
treef480da30ea734f360e8df8ee1cd9320e3ba85b56
parentbb6c338b9e670cf70d21927770f424cee38e06f6 (diff)
pkg/compiler: fix root node not visited in typedef checks
Without this fix, the compiler throws an error 'template argument BASE is not used' for the following typedef. type templ1[BASE] BASE foo(a ptr[in, templ1[int64]]) Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
-rw-r--r--pkg/compiler/check.go4
-rw-r--r--pkg/compiler/testdata/all.txt2
2 files changed, 4 insertions, 2 deletions
diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go
index adf6f4e9d..24f0a13be 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.PostRecursive(func(n ast.Node) {
+ ast.PostRecursive(func(n ast.Node) {
templArg, ok := n.(*ast.Type)
if !ok {
return
@@ -972,7 +972,7 @@ func (comp *compiler) instantiate(templ ast.Node, params []*ast.Ident, args []*a
col.Pos = concreteArg.Pos
}
}
- }))
+ })(templ)
for _, param := range params {
if !argUsed[param.Name] {
comp.error(argMap[param.Name].Pos,
diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt
index 68629c685..9bb2c3d16 100644
--- a/pkg/compiler/testdata/all.txt
+++ b/pkg/compiler/testdata/all.txt
@@ -224,6 +224,7 @@ type templ_struct4 templ_struct3
type templ_struct5 templ_struct0[C1, templ_struct0[C2, int8]]
type templ_struct6 templ_struct0[C1, templ_struct2[C2]]
type templ_union union_with_templ_struct
+type templ_base3[BASE] BASE
foo$templ0(a templ0[42, int8])
foo$templ1(a ptr[in, templ_struct0[C2, int8]])
@@ -234,6 +235,7 @@ foo$templ5(a ptr[in, templ_struct1[3]])
foo$templ6(a ptr[in, templ_struct4])
foo$templ7(a ptr[in, templ_struct5], b ptr[in, templ_struct6], c ptr[in, templ_union], d ptr[in, type3])
foo$templ8(a ptr[in, templ_templ_use])
+foo$templ9(a ptr[in, templ_base3[int64]])
# Structs.