Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: value decl loop #2074

Merged
merged 12 commits into from
Sep 12, 2024
60 changes: 44 additions & 16 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
// skip declarations already predefined
// (e.g. through recursion for a
// dependent)
} else {
// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)
fn.Decls[i] = d2
continue

Check warning on line 48 in gnovm/pkg/gnolang/preprocess.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/preprocess.go#L48

Added line #L48 was not covered by tests
}

// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)
fn.Decls[i] = d2
}
}
}
Expand All @@ -63,11 +64,12 @@
// skip declarations already predefined
// (e.g. through recursion for a
// dependent)
} else {
// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)
fn.Decls[i] = d2
continue
}

// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)
fn.Decls[i] = d2
}
}
}
Expand All @@ -81,11 +83,12 @@
// skip declarations already predefined
// (e.g. through recursion for a
// dependent)
} else {
// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)
fn.Decls[i] = d2
continue

Check warning on line 86 in gnovm/pkg/gnolang/preprocess.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/preprocess.go#L86

Added line #L86 was not covered by tests
}

// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)
fn.Decls[i] = d2
}
}
}
Expand All @@ -97,11 +100,36 @@
if d.GetAttribute(ATTR_PREDEFINED) == true {
// skip declarations already predefined (e.g.
// through recursion for a dependent)
} else {
// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)
fn.Decls[i] = d2
continue
}

if vd, ok := d.(*ValueDecl); ok && len(vd.NameExprs) > 1 && len(vd.Values) == len(vd.NameExprs) {
petar-dambovaliev marked this conversation as resolved.
Show resolved Hide resolved
split := make([]Decl, len(vd.NameExprs))

for j := 0; j < len(vd.NameExprs); j++ {
base := vd.Copy().(*ValueDecl)
base.NameExprs = NameExprs{NameExpr{
Attributes: base.NameExprs[j].Attributes,
Path: base.NameExprs[j].Path,
Name: base.NameExprs[j].Name,
}}

if j < len(base.Values) {
base.Values = Exprs{base.Values[j].Copy().(Expr)}
}

split[j], _ = predefineNow(store, fn, base)
}

fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) //nolint:makezero
i += len(vd.NameExprs)
continue
}

Check warning on line 127 in gnovm/pkg/gnolang/preprocess.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/preprocess.go#L127

Added line #L127 was not covered by tests

// recursively predefine dependencies.
d2, _ := predefineNow(store, fn, d)

fn.Decls[i] = d2
ltzmaxwell marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
1 change: 1 addition & 0 deletions gnovm/tests/files/var19.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

func main() {
var a, b, c = 1, a+1

println(a)
println(b)
println(c)
Expand Down
14 changes: 14 additions & 0 deletions gnovm/tests/files/var29.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

func main() {
println(a)
println(b)
println(c)
}

var a, b, c = 1, a + 1, b + 1

// Output:
// 1
// 2
// 3
17 changes: 17 additions & 0 deletions gnovm/tests/files/var30.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

func main() {
println(a)
println(b)
println(c)
println(d)
}

var a, b, c = 1, a + d, 3
var d = a

// Output:
// 1
// 2
// 3
// 1
Loading