interp: add missing conversion for non integer array dimension
Fixes #1451.
This commit is contained in:
@@ -446,12 +446,19 @@ func nodeType2(interp *Interpreter, sc *scope, n *node, seen []*node) (t *itype,
|
||||
)
|
||||
switch v := c0.rval; {
|
||||
case v.IsValid():
|
||||
// Size if defined by a constant litteral value.
|
||||
// Size if defined by a constant literal value.
|
||||
if isConstantValue(v.Type()) {
|
||||
c := v.Interface().(constant.Value)
|
||||
length = constToInt(c)
|
||||
} else {
|
||||
length = int(v.Int())
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
length = int(v.Int())
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
length = int(v.Uint())
|
||||
default:
|
||||
return nil, c0.cfgErrorf("non integer constant %v", v)
|
||||
}
|
||||
}
|
||||
case c0.kind == ellipsisExpr:
|
||||
// [...]T expression, get size from the length of composite array.
|
||||
|
||||
Reference in New Issue
Block a user