Skip to content

Commit 73253fa

Browse files
committed
Fix bug with compiling integer values to interface{} types.
1 parent 75e76e6 commit 73253fa

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Changelog
22

3+
## v1.4.2
4+
* Fixed bug with compiling integer values to interface{} types.
5+
36
## v1.4.1
4-
* Added bounds check for slice operations `foo[0:5]`
7+
* Added bounds check for slice operations `foo[0:5]`.
58

69
## v1.4.0
710
* Added option to allow using undefined variables.

compiler/compiler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (c *compiler) IntegerNode(node *ast.IntegerNode) {
213213
c.emitPush(uint64(node.Value))
214214

215215
default:
216-
panic(fmt.Sprintf("cannot compile %v to %v", node.Value, node.GetType()))
216+
c.emitPush(node.Value)
217217
}
218218
}
219219

expr_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,10 @@ func TestExpr(t *testing.T) {
789789
`String[7:9]`,
790790
"",
791791
},
792+
{
793+
`Float(0)`,
794+
float64(0),
795+
},
792796
}
793797

794798
for _, tt := range tests {
@@ -929,6 +933,17 @@ func (*mockEnv) Variadic(x string, xs ...int) []int {
929933
return xs
930934
}
931935

936+
func (*mockEnv) Float(i interface{}) float64 {
937+
switch t := i.(type) {
938+
case int:
939+
return float64(t)
940+
case float64:
941+
return t
942+
default:
943+
panic("unexpected type")
944+
}
945+
}
946+
932947
type ticket struct {
933948
Price int
934949
}

0 commit comments

Comments
 (0)