Skip to content
Merged
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
28 changes: 11 additions & 17 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,6 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
// LEAVE (FUNC) CALL EXPR SPECIAL CASES:
//----------------------------------------

isBuiltinMake := false
// NOTE: these appear to be actually special cases in go.
// In general, a string is not assignable to []bytes
// without conversion.
Expand Down Expand Up @@ -1775,7 +1774,16 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
}
}
case "make":
isBuiltinMake = true
// make's variadic params are declared as Vrd(AnyT()), so untyped
// constants won't be automatically coerced to int; enforce it here.
for i := range n.Args[1:] {
at := evalStaticTypeOf(store, last, n.Args[i+1])
if isUntyped(at) {
checkOrConvertType(store, last, n, &n.Args[i+1], IntType)
} else if !isInteger(at) {
panic(fmt.Sprintf("invalid argument: index %v (variable of type %v) must be integer", n.Args[i+1], at))
}
}
case "_cross_gno0p0":
if ctxpn.GetAttribute(ATTR_FIX_FROM) == GnoVerMissing {
// This is only backwards compatibility for the gno 0.9
Expand Down Expand Up @@ -2017,21 +2025,7 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
}
checkOrConvertType(store, last, n, &n.Args[i], spts[i].Type)
} else {
expectedType := spts[len(spts)-1].Type.Elem()

// SPECIAL CASE: 'make' variadic arguments are untyped sizes
// that must default to 'int' if no type is explicitly provided.
if isBuiltinMake {
at := evalStaticTypeOf(store, last, n.Args[i])
switch {
case isUntyped(at):
expectedType = IntType
case !isInteger(at):
panic(fmt.Sprintf("invalid argument: index %v (variable of type %v) must be integer", n.Args[i], at))
}
}

checkOrConvertType(store, last, n, &n.Args[i], expectedType)
checkOrConvertType(store, last, n, &n.Args[i], spts[len(spts)-1].Type.Elem())
}
} else {
checkOrConvertType(store, last, n, &n.Args[i], spts[i].Type)
Expand Down
Loading