From 70625002b6b3ba280c700636ed8314f20e1384a7 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 19 Jun 2024 13:55:21 +0200 Subject: fix (parser): don't panic if assign of define untyped value In case of defining or assigning to untyped value, the type has to be taken from the source value instead of the target value. The vm test coverage has also been slightly improved. --- parser/interpreter_test.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'parser/interpreter_test.go') diff --git a/parser/interpreter_test.go b/parser/interpreter_test.go index a6ad246..314f35b 100644 --- a/parser/interpreter_test.go +++ b/parser/interpreter_test.go @@ -69,6 +69,7 @@ func TestExpr(t *testing.T) { {src: "-2 + 5", res: "3"}, {src: "5 + -2", res: "3"}, {src: "!false", res: "true"}, + {src: `a := "hello"`, res: "hello"}, }) } @@ -233,6 +234,7 @@ func TestVar(t *testing.T) { {src: "var a, b int = 2, 5; a+b", res: "7"}, {src: "var x = 5; x", res: "5"}, {src: "var a = 1; func f() int { var a, b int = 3, 4; return a+b}; a+f()", res: "8"}, + {src: `var a = "hello"; a`, res: "hello"}, {src: `var ( a, b int = 4+1, 3 c = 8 -- cgit v1.2.3