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:
Evgenii Stratonikov 2020-10-06 18:25:40 +03:00
parent 2d9ef9219a
commit 6701e8cda0
4 changed files with 58 additions and 27 deletions

View file

@ -24,11 +24,13 @@ func TestInit(t *testing.T) {
var m = map[int]int{}
var a = 2
func init() {
m[1] = 11
b := 11
m[1] = b
}
func init() {
a = 1
m[3] = 30
var b int
m[3] = 30 + b
}
func Main() int {
return m[1] + m[3] + a