diff --git a/lang/interpret_test/TestAstFunc1/fail2.graph b/lang/interpret_test/TestAstFunc1/fail2.graph new file mode 100644 index 00000000..456bf1cb --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/fail2.graph @@ -0,0 +1 @@ +# err: can't unify, invariant illogicality with equality: base kind does not match (2 != 3) diff --git a/lang/interpret_test/TestAstFunc1/fail2/main.mcl b/lang/interpret_test/TestAstFunc1/fail2/main.mcl new file mode 100644 index 00000000..0ca8a2de --- /dev/null +++ b/lang/interpret_test/TestAstFunc1/fail2/main.mcl @@ -0,0 +1,9 @@ +import "fmt" +$x str = if true { # should fail unification + 42 +} else { + 13 +} +test "t1" { + anotherstr => fmt.printf("hello %s", $x), +} diff --git a/lang/unification_test.go b/lang/unification_test.go index 664e1608..6cb55cd4 100644 --- a/lang/unification_test.go +++ b/lang/unification_test.go @@ -645,6 +645,61 @@ func TestUnification1(t *testing.T) { }, }) } + { + //import "fmt" + //$x str = if true { # should fail unification + // 42 + //} else { + // 13 + //} + //test "t1" { + // stringptr => fmt.printf("hello %s", $x), + //} + cond := &ExprIf{ + Condition: &ExprBool{V: true}, + ThenBranch: &ExprInt{V: 42}, + ElseBranch: &ExprInt{V: 13}, + } + cond.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: "x", // the var + Value: cond, + }, + &StmtRes{ + Kind: "test", + Name: &ExprStr{V: "t1"}, + Contents: []StmtResContents{ + &StmtResField{ + Field: "anotherstr", + Value: expr, + }, + }, + }, + }, + } + testCases = append(testCases, test{ + name: "typed if expr", + ast: stmt, + fail: true, + experrstr: "can't unify, invariant illogicality with equality: base kind does not match (2 != 3)", + }) + } names := []string{} for index, tc := range testCases { // run all the tests