Skip to content

Commit

Permalink
fix(gnovm): set Loc Line on Decl (gnolang#2221)
Browse files Browse the repository at this point in the history
Closes gnolang#2220
<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
omarsy authored Jun 3, 2024
1 parent e8af2a4 commit ed2835d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/gno_test/lint_bad_import.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ func main() {

-- stdout.golden --
-- stderr.golden --
bad_file.gno:1: unknown import path python (code=2).
bad_file.gno:3: unknown import path python (code=2).
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

! stdout .+
stderr 'panic: unknown import path net \[recovered\]'
stderr ' panic: gno.land/r/\w{8}/contract.gno:1: unknown import path net'
stderr ' panic: gno.land/r/\w{8}/contract.gno:3: unknown import path net'

gno test -v --with-native-fallback .

Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/testdata/gno_test/unknow_lib.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

! stdout .+
stderr 'panic: unknown import path foobarbaz \[recovered\]'
stderr ' panic: gno.land/r/\w{8}/contract.gno:1: unknown import path foobarbaz'
stderr ' panic: gno.land/r/\w{8}/contract.gno:3: unknown import path foobarbaz'

! gno test -v --with-native-fallback .

! stdout .+
stderr 'panic: unknown import path foobarbaz \[recovered\]'
stderr ' panic: gno.land/r/\w{8}/contract.gno:1: unknown import path foobarbaz'
stderr ' panic: gno.land/r/\w{8}/contract.gno:3: unknown import path foobarbaz'

-- contract.gno --
package contract
Expand Down
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ func TestDebug(t *testing.T) {
{in: "p 'a'\n", out: "(97 int32)"},
{in: "p '界'\n", out: "(30028 int32)"},
{in: "p \"xxxx\"\n", out: `("xxxx" string)`},
{in: "si\n", out: "sample.gno:4"},
{in: "s\ns\n", out: "=> 33: num := 5"},
{in: "si\n", out: "sample.gno:14"},
{in: "s\ns\n", out: `=> 14: var global = "test"`},
{in: "s\n\n", out: "=> 33: num := 5"},
{in: "foo", out: "command not available: foo"},
{in: "\n\n", out: "dbg> "},
{in: "#\n", out: "dbg> "},
{in: "p foo", out: "Command failed: could not find symbol value for foo"},
{in: "b +7\nc\n", out: "=> 11:"},
{in: "b +7\nc\n", out: "=> 21: r := t.A[i]"},
{in: brk + "clear 0\n", out: "dbg> "},
{in: brk + "clear -1\n", out: "Command failed: invalid breakpoint id: -1"},
{in: brk + "clear\n", out: "dbg> "},
Expand Down
9 changes: 7 additions & 2 deletions gnovm/pkg/gnolang/go2gno.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ func toDecls(fs *token.FileSet, gd *ast.GenDecl) (ds Decls) {
Const: true,
}
cd.SetAttribute(ATTR_IOTA, si)
setLoc(fs, s.Pos(), cd)
ds = append(ds, cd)
} else {
var names []NameExpr
Expand All @@ -785,23 +786,27 @@ func toDecls(fs *token.FileSet, gd *ast.GenDecl) (ds Decls) {
Values: values,
Const: false,
}
setLoc(fs, s.Pos(), vd)
ds = append(ds, vd)
}
case *ast.ImportSpec:
path, err := strconv.Unquote(s.Path.Value)
if err != nil {
panic("unexpected import spec path type")
}
ds = append(ds, &ImportDecl{
im := &ImportDecl{
NameExpr: *Nx(toName(s.Name)),
PkgPath: path,
})
}
setLoc(fs, s.Pos(), im)
ds = append(ds, im)
default:
panic(fmt.Sprintf(
"unexpected decl spec %v",
reflect.TypeOf(s)))
}
}

return ds
}

Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/const9.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Error:
// main/files/const9.gno:1: constant definition loop with b
// main/files/const9.gno:5: constant definition loop with b
2 changes: 1 addition & 1 deletion gnovm/tests/files/import6.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ func main() {
}

// Error:
// github.com/gnolang/gno/_test/c2/c2.gno:1: import cycle detected: "github.com/gnolang/gno/_test/c1" (through [github.com/gnolang/gno/_test/c1 github.com/gnolang/gno/_test/c2])
// github.com/gnolang/gno/_test/c2/c2.gno:3: import cycle detected: "github.com/gnolang/gno/_test/c1" (through [github.com/gnolang/gno/_test/c1 github.com/gnolang/gno/_test/c2])
8 changes: 8 additions & 0 deletions gnovm/tests/files/var18.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

func main() {
a, b, c := 1, 2
}

// Error:
// main/files/var18.gno:4: should not happen

0 comments on commit ed2835d

Please sign in to comment.