From fdfcb9c1df4e928cba5a70c3344ec3bf16bf2fd9 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 9 Mar 2021 11:58:04 +0100 Subject: [PATCH] interp: do not check properties of incomplete types Fixes #1042. --- _test/const25.go | 11 +++++++++++ interp/cfg.go | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 _test/const25.go diff --git a/_test/const25.go b/_test/const25.go new file mode 100644 index 00000000..7cb053da --- /dev/null +++ b/_test/const25.go @@ -0,0 +1,11 @@ +package main + +const ( + FGBlack Attribute = iota + 30 +) + +type Attribute int + +func main() { + println(FGBlack) +} diff --git a/interp/cfg.go b/interp/cfg.go index d9a7d015..67a79caa 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -82,8 +82,15 @@ func (interp *Interpreter) cfg(root *node, importPath string) ([]*node, error) { i-- } dest := a.child[i] - if dest.typ != nil && !isInterface(dest.typ) { - // Interface type are not propagated, and will be resolved at post-order. + if dest.typ == nil { + break + } + if dest.typ.incomplete { + err = n.cfgErrorf("invalid type declaration") + return false + } + if !isInterface(dest.typ) { + // Interface types are not propagated, and will be resolved at post-order. n.typ = dest.typ } case binaryExpr, unaryExpr, parenExpr: