fix: allow uint in make len and cap

This commit is contained in:
Nicholas Wiersma
2020-06-18 15:18:04 +02:00
committed by GitHub
parent 7323d97023
commit 0643762852
2 changed files with 16 additions and 4 deletions

12
_test/make2.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import "fmt"
func main() {
var s uint = 4
t := make([]int, s)
fmt.Println(t)
}
// Output:
// [0 0 0 0]

View File

@@ -2443,14 +2443,14 @@ func _make(n *node) {
switch len(n.child) {
case 3:
n.exec = func(f *frame) bltn {
len := int(value(f).Int())
len := int(vInt(value(f)))
dest(f).Set(reflect.MakeSlice(typ, len, len))
return next
}
case 4:
value1 := genValue(n.child[3])
n.exec = func(f *frame) bltn {
dest(f).Set(reflect.MakeSlice(typ, int(value(f).Int()), int(value1(f).Int())))
dest(f).Set(reflect.MakeSlice(typ, int(vInt(value(f))), int(vInt(value1(f)))))
return next
}
}
@@ -2465,7 +2465,7 @@ func _make(n *node) {
case 3:
value := genValue(n.child[2])
n.exec = func(f *frame) bltn {
dest(f).Set(reflect.MakeChan(typ, int(value(f).Int())))
dest(f).Set(reflect.MakeChan(typ, int(vInt(value(f)))))
return next
}
}
@@ -2480,7 +2480,7 @@ func _make(n *node) {
case 3:
value := genValue(n.child[2])
n.exec = func(f *frame) bltn {
dest(f).Set(reflect.MakeMapWithSize(typ, int(value(f).Int())))
dest(f).Set(reflect.MakeMapWithSize(typ, int(vInt(value(f)))))
return next
}
}