fix: handle type for unary expression (#108)

This commit is contained in:
Marc Vertes
2019-02-25 15:38:48 +01:00
committed by Ludovic Fernandez
parent c8693ba672
commit 0fb2370c33
2 changed files with 11 additions and 0 deletions

View File

@@ -218,6 +218,14 @@ func TestEvalCompositeArray0(t *testing.T) {
}
}
func TestEvalUnary0(t *testing.T) {
i := interp.New(interp.Opt{})
v := evalCheck(t, i, `a := -1`)
if expected := "-1"; fmt.Sprintf("%v", v) != expected {
t.Fatalf("Expected %v, got %v", expected, v)
}
}
func evalCheck(t *testing.T, i *interp.Interpreter, src string) reflect.Value {
t.Helper()

View File

@@ -193,6 +193,9 @@ func nodeType(interp *Interpreter, scope *Scope, n *Node) (*Type, error) {
err = n.cfgError("missign support for type %T", n.val)
}
case UnaryExpr:
t, err = nodeType(interp, scope, n.child[0])
case BinaryExpr:
t, err = nodeType(interp, scope, n.child[0])
if err != nil {