mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
compiler: allow to use local variables in init()
Because body of multiple `init()` functions constitute single method in contract, we initialize slot with maximum amount of locals encounterered in any of `init()` functions and clear them before emitting body of each instance of `init()`.
This commit is contained in:
parent
2d9ef9219a
commit
6701e8cda0
4 changed files with 58 additions and 27 deletions
|
@ -152,10 +152,10 @@ func (c *funcScope) analyzeVoidCalls(node ast.Node) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (c *funcScope) countLocals() int {
|
||||
func countLocals(decl *ast.FuncDecl) (int, bool) {
|
||||
size := 0
|
||||
hasDefer := false
|
||||
ast.Inspect(c.decl, func(n ast.Node) bool {
|
||||
ast.Inspect(decl, func(n ast.Node) bool {
|
||||
switch n := n.(type) {
|
||||
case *ast.FuncType:
|
||||
num := n.Results.NumFields()
|
||||
|
@ -186,6 +186,11 @@ func (c *funcScope) countLocals() int {
|
|||
}
|
||||
return true
|
||||
})
|
||||
return size, hasDefer
|
||||
}
|
||||
|
||||
func (c *funcScope) countLocals() int {
|
||||
size, hasDefer := countLocals(c.decl)
|
||||
if hasDefer {
|
||||
c.finallyProcessedIndex = size
|
||||
size++
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue