From de3e24c4b6cd0136618ce74eb025a15d4834c082 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 23 Jan 2018 10:44:01 +0100 Subject: pkg/compiler: allow strings as template arguments Needed for netfilter descriptions. --- pkg/compiler/check.go | 7 +------ pkg/compiler/testdata/all.txt | 2 ++ pkg/compiler/testdata/errors.txt | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) (limited to 'pkg') diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 4187f8a96..5d741effc 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -670,12 +670,6 @@ func (comp *compiler) replaceTypedef(ctx *checkCtx, t *ast.Type, desc *typeDesc, ctx.instantiationStack = append(ctx.instantiationStack, fullTypeName) nargs := len(typedef.Args) args := t.Args - for _, arg := range args { - if arg.String != "" { - comp.error(arg.Pos, "template arguments can't be strings (%q)", arg.String) - return - } - } if nargs != len(t.Args) { if nargs == 0 { comp.error(t.Pos, "type %v is not a template", typedefName) @@ -734,6 +728,7 @@ func (comp *compiler) instantiate(templ ast.Node, params []*ast.Ident, args []*a // TODO(dvyukov): somewhat hacky, but required for int8[0:CONST_ARG] // Need more checks here. E.g. that CONST_ARG does not have subargs. // And if CONST_ARG is a value, then use concreteArg.Value. + // Also need to error if CONST_ARG is a string. if concreteArg := argMap[templArg.Ident2]; concreteArg != nil { templArg.Ident2 = concreteArg.Ident templArg.Pos2 = concreteArg.Pos diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index ad04364b0..088e119ef 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -86,6 +86,8 @@ bitfield0 { type type0 int8 type templ0[A, B] const[A, B] +type templ2[STR] string[STR] +type type3 templ2["a"] type templ_struct0[A, B] { len len[parent, int16] diff --git a/pkg/compiler/testdata/errors.txt b/pkg/compiler/testdata/errors.txt index 6a9bcbae3..8d0a9db1b 100644 --- a/pkg/compiler/testdata/errors.txt +++ b/pkg/compiler/testdata/errors.txt @@ -266,5 +266,4 @@ foo$202(a templ0) ### template templ0 needs 2 arguments instead of 0 foo$203(a type0[42]) ### type type0 is not a template foo$204(a ptr[in, templ_struct0[42, int8]]) foo$205(a ptr[in, templ_struct0[int8, int8]]) -foo$206(a ptr[in, templ_struct1["foo"]]) ### template arguments can't be strings ("foo") foo$207(a ptr[in, templ_struct2[1]]) -- cgit mrf-deployment