compiler: calculate local variables properly
In case when right-hand side of an assignment is a function, left-hand side should be used.
This commit is contained in:
parent
84c36326f5
commit
b18a7f200c
2 changed files with 13 additions and 1 deletions
|
@ -124,7 +124,7 @@ func (c *funcScope) countLocals() int {
|
||||||
}
|
}
|
||||||
case *ast.AssignStmt:
|
case *ast.AssignStmt:
|
||||||
if n.Tok == token.DEFINE {
|
if n.Tok == token.DEFINE {
|
||||||
size += len(n.Rhs)
|
size += len(n.Lhs)
|
||||||
}
|
}
|
||||||
case *ast.ReturnStmt, *ast.IfStmt:
|
case *ast.ReturnStmt, *ast.IfStmt:
|
||||||
size++
|
size++
|
||||||
|
|
|
@ -38,6 +38,18 @@ func TestMultiDeclaration(t *testing.T) {
|
||||||
eval(t, src, big.NewInt(6))
|
eval(t, src, big.NewInt(6))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCountLocal(t *testing.T) {
|
||||||
|
src := `package foo
|
||||||
|
func Main() int {
|
||||||
|
a, b, c, d := f()
|
||||||
|
return a + b + c + d
|
||||||
|
}
|
||||||
|
func f() (int, int, int, int) {
|
||||||
|
return 1, 2, 3, 4
|
||||||
|
}`
|
||||||
|
eval(t, src, big.NewInt(10))
|
||||||
|
}
|
||||||
|
|
||||||
func TestMultiDeclarationLocal(t *testing.T) {
|
func TestMultiDeclarationLocal(t *testing.T) {
|
||||||
src := `package foo
|
src := `package foo
|
||||||
func Main() int {
|
func Main() int {
|
||||||
|
|
Loading…
Reference in a new issue