From 9d28ff9b2300953efd3feb37f50f3afc1b895343 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 20 Jan 2019 04:00:02 -0500 Subject: [PATCH] lang: unification: Catch unification error on typed var expr This was similar to the typed if expr error. --- lang/unification_test.go | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lang/unification_test.go b/lang/unification_test.go index 6cb55cd4..9076d41d 100644 --- a/lang/unification_test.go +++ b/lang/unification_test.go @@ -700,6 +700,59 @@ func TestUnification1(t *testing.T) { experrstr: "can't unify, invariant illogicality with equality: base kind does not match (2 != 3)", }) } + { + //import "fmt" + //$w = true + //$x str = $w # should fail unification + //test "t1" { + // stringptr => fmt.printf("hello %s", $x), + //} + wvar := &ExprBool{V: true} + xvar := &ExprVar{Name: "w"} + xvar.SetType(types.TypeStr) // should fail unification + expr := &ExprCall{ + Name: "fmt.printf", + Args: []interfaces.Expr{ + &ExprStr{ + V: "hello %s", + }, + &ExprVar{ + Name: "x", // the var + }, + }, + } + stmt := &StmtProg{ + Prog: []interfaces.Stmt{ + &StmtImport{ + Name: "fmt", + }, + &StmtBind{ + Ident: "w", + Value: wvar, + }, + &StmtBind{ + Ident: "x", // the var + Value: xvar, + }, + &StmtRes{ + Kind: "test", + Name: &ExprStr{V: "t1"}, + Contents: []StmtResContents{ + &StmtResField{ + Field: "anotherstr", + Value: expr, + }, + }, + }, + }, + } + testCases = append(testCases, test{ + name: "typed var expr", + ast: stmt, + fail: true, + experrstr: "can't unify, invariant illogicality with equality: base kind does not match (2 != 1)", + }) + } names := []string{} for index, tc := range testCases { // run all the tests