Skip to content

Commit

Permalink
interp: fix support of type assert expressions in the global scope
Browse files Browse the repository at this point in the history
Add the support of type assert expressions in type parsing
which allows to process type assertions in the global scope.

Fixes #1543.
  • Loading branch information
mvertes committed Apr 26, 2023
1 parent dc7c64b commit 68a430f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions _test/assert4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

var cc interface{} = 2
var dd = cc.(int)

func main() {
println(dd)
}

// Output:
// 2
3 changes: 3 additions & 0 deletions interp/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 68a430f

Please sign in to comment.