interp: retry type definition if an array size is undefined
In case of forward definition of a constant, a symbol may be undefined when attempting to compute the array size in type analysis. Just mark the type as incomplete instead of aborting directly, to allow resolution at a second pass. Fixes #1470.
This commit is contained in:
15
_test/issue-1470.go
Normal file
15
_test/issue-1470.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
type T struct {
|
||||
num [tnum + 2]int
|
||||
}
|
||||
|
||||
const tnum = 23
|
||||
|
||||
func main() {
|
||||
t := T{}
|
||||
println(len(t.num))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 25
|
||||
@@ -483,7 +483,11 @@ func nodeType2(interp *Interpreter, sc *scope, n *node, seen []*node) (t *itype,
|
||||
length = int(vInt(sym.rval))
|
||||
default:
|
||||
// Size is defined by a numeric constant expression.
|
||||
if _, err = interp.cfg(c0, sc, sc.pkgID, sc.pkgName); err != nil {
|
||||
if _, err := interp.cfg(c0, sc, sc.pkgID, sc.pkgName); err != nil {
|
||||
if strings.Contains(err.Error(), " undefined: ") {
|
||||
incomplete = true
|
||||
break
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
v, ok := c0.rval.Interface().(constant.Value)
|
||||
|
||||
Reference in New Issue
Block a user