From 68a430f969c811146f53e0f039025a7fb0d29342 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 26 Apr 2023 10:52:05 +0200 Subject: [PATCH] interp: fix support of type assert expressions in the global scope Add the support of type assert expressions in type parsing which allows to process type assertions in the global scope. Fixes #1543. --- _test/assert4.go | 11 +++++++++++ interp/type.go | 3 +++ 2 files changed, 14 insertions(+) create mode 100644 _test/assert4.go diff --git a/_test/assert4.go b/_test/assert4.go new file mode 100644 index 00000000..dcf3f684 --- /dev/null +++ b/_test/assert4.go @@ -0,0 +1,11 @@ +package main + +var cc interface{} = 2 +var dd = cc.(int) + +func main() { + println(dd) +} + +// Output: +// 2 diff --git a/interp/type.go b/interp/type.go index 39b5f903..6c493b31 100644 --- a/interp/type.go +++ b/interp/type.go @@ -1093,6 +1093,9 @@ func nodeType2(interp *Interpreter, sc *scope, n *node, seen []*node) (t *itype, sc.sym[sname].typ = t } + case typeAssertExpr: + t, err = nodeType2(interp, sc, n.child[1], seen) + default: err = n.cfgErrorf("type definition not implemented: %s", n.kind) }