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.
This commit is contained in:
Marc Vertes
2023-04-26 10:52:05 +02:00
committed by GitHub
parent dc7c64ba88
commit 68a430f969
2 changed files with 14 additions and 0 deletions

11
_test/assert4.go Normal file
View File

@@ -0,0 +1,11 @@
package main
var cc interface{} = 2
var dd = cc.(int)
func main() {
println(dd)
}
// Output:
// 2

View File

@@ -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)
}