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: set Loc Line on Decl #2221

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -101,14 +101,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
thehowl marked this conversation as resolved.
Show resolved Hide resolved
// 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
thehowl marked this conversation as resolved.
Show resolved Hide resolved
Loading