Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile error for functions with int64 parameters #662

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@
}
c.emitPush(int32(node.Value))
case reflect.Int64:
panic(fmt.Sprintf("constant %d overflows int64", node.Value))
if node.Value > math.MaxInt64 || node.Value < math.MinInt64 {

Check failure on line 348 in compiler/compiler.go

View workflow job for this annotation

GitHub Actions / test (1.18, 386)

math.MaxInt64 (untyped int constant 9223372036854775807) overflows int

Check failure on line 348 in compiler/compiler.go

View workflow job for this annotation

GitHub Actions / test (1.18, 386)

math.MinInt64 (untyped int constant -9223372036854775808) overflows int

Check failure on line 348 in compiler/compiler.go

View workflow job for this annotation

GitHub Actions / test (1.22, 386)

math.MaxInt64 (untyped int constant 9223372036854775807) overflows int

Check failure on line 348 in compiler/compiler.go

View workflow job for this annotation

GitHub Actions / test (1.22, 386)

math.MinInt64 (untyped int constant -9223372036854775808) overflows int
panic(fmt.Sprintf("constant %d overflows int64", node.Value))
}
c.emitPush(int64(node.Value))
case reflect.Uint:
if node.Value < 0 {
Expand Down
20 changes: 20 additions & 0 deletions compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,23 @@ func TestCompile_optimizes_jumps(t *testing.T) {
})
}
}

func TestCompile_IntegerArgsFunc(t *testing.T) {
env := mock.Env{}
codes := []string{
"FuncInt(0)",
"FuncInt8(0)",
"FuncInt16(0)",
"FuncInt32(0)",
"FuncInt64(0)",
"FuncUint(0)",
"FuncUint8(0)",
"FuncUint16(0)",
"FuncUint32(0)",
"FuncUint64(0)",
}
for _, code := range codes {
_, err := expr.Compile(code, expr.Env(env))
require.NoError(t, err)
}
}
40 changes: 40 additions & 0 deletions test/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading