fix: check array size symbol kind

When determining the size of an array and a symbol is found, the symbol must be a const for the type to be valid. 

While it makes sense for this check to be done in type checking, the type can be determined by GTA which would then fail. For now this check is done when getting the node type.

Fixes #825
This commit is contained in:
Nicholas Wiersma
2020-08-27 11:52:04 +02:00
committed by GitHub
parent 358a57b4b9
commit e332a6b3be
2 changed files with 6 additions and 0 deletions

View File

@@ -182,6 +182,9 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
t.size = arrayTypeLen(n.anc)
default:
if sym, _, ok := sc.lookup(n.child[0].ident); ok {
if sym.kind != constSym {
return nil, n.child[0].cfgErrorf("non-constant array bound %q", n.child[0].ident)
}
// Resolve symbol to get size value
if sym.typ != nil && sym.typ.cat == intT {
if v, ok := sym.rval.Interface().(int); ok {