From 6287988c7f1b3b1d3c52e66945602fd42e55e50a Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Mon, 27 May 2024 11:34:38 +0200 Subject: [PATCH] Fix function calls with int64 params --- compiler/compiler.go | 1 - compiler/compiler_test.go | 22 +++++++++++++++++++++ test/mock/mock.go | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index 205d6023..720f6a26 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -345,7 +345,6 @@ func (c *compiler) IntegerNode(node *ast.IntegerNode) { } c.emitPush(int32(node.Value)) case reflect.Int64: - panic(fmt.Sprintf("constant %d overflows int64", node.Value)) c.emitPush(int64(node.Value)) case reflect.Uint: if node.Value < 0 { diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index eb7f3d32..ba5d6dc5 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -628,3 +628,25 @@ func TestCompile_optimizes_jumps(t *testing.T) { }) } } + +func TestCompile_IntegerArgsFunc(t *testing.T) { + env := mock.Env{} + tests := []struct{ code string }{ + {"FuncInt(0)"}, + {"FuncInt8(0)"}, + {"FuncInt16(0)"}, + {"FuncInt32(0)"}, + {"FuncInt64(0)"}, + {"FuncUint(0)"}, + {"FuncUint8(0)"}, + {"FuncUint16(0)"}, + {"FuncUint32(0)"}, + {"FuncUint64(0)"}, + } + for _, tt := range tests { + t.Run(tt.code, func(t *testing.T) { + _, err := expr.Compile(tt.code, expr.Env(env)) + require.NoError(t, err) + }) + } +} diff --git a/test/mock/mock.go b/test/mock/mock.go index 5c0fa9e3..fc91652f 100644 --- a/test/mock/mock.go +++ b/test/mock/mock.go @@ -65,6 +65,46 @@ func (p Env) FuncTyped(_ string) int { return 2023 } +func (p Env) FuncInt(_ int) int { + return 0 +} + +func (p Env) FuncUint(_ uint) int { + return 0 +} + +func (p Env) FuncInt8(_ float64) int { + return 0 +} + +func (p Env) FuncInt16(_ int16) int { + return 0 +} + +func (p Env) FuncInt32(_ int32) int { + return 0 +} + +func (p Env) FuncInt64(_ int64) int { + return 0 +} + +func (p Env) FuncUint8(_ uint8) int { + return 0 +} + +func (p Env) FuncUint16(_ uint16) int { + return 0 +} + +func (p Env) FuncUint32(_ uint32) int { + return 0 +} + +func (p Env) FuncUint64(_ uint64) int { + return 0 +} + func (p Env) TimeEqualString(a time.Time, s string) bool { return a.Format("2006-01-02") == s }