lang: ast: Ensure a list doesn't sneak through type interpolation

If we had a single list wrapped in an interpolated string, it could
sneak through type unification, which is not correct. Wrapping a
variable by interpolation in a string, must force it to be a string.
This commit is contained in:
James Shubin
2024-03-20 18:06:29 -04:00
parent 340a832884
commit 946468dc99
8 changed files with 81 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ import (
"github.com/purpleidea/mgmt/lang/funcs"
"github.com/purpleidea/mgmt/lang/interfaces"
"github.com/purpleidea/mgmt/lang/parser"
"github.com/purpleidea/mgmt/lang/types"
"github.com/purpleidea/mgmt/util"
"github.com/davecgh/go-spew/spew"
@@ -384,6 +385,9 @@ func TestInterpolateBasicStmt(t *testing.T) {
},
},
}
if err := resName.SetType(types.TypeStr); err != nil {
panic("could not set type")
}
exp := &ast.StmtProg{
Body: []interfaces.Stmt{
&ast.StmtRes{
@@ -574,6 +578,9 @@ func TestInterpolateBasicExpr(t *testing.T) {
},
},
}
if err := exp.SetType(types.TypeStr); err != nil {
panic("could not set type")
}
testCases = append(testCases, test{
name: "basic expansion",
ast: xast,