Skip to content

Commit

Permalink
fix: set loc don't use line from group of declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed May 29, 2024
1 parent 0fa39be commit eaab6e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestDebug(t *testing.T) {
{in: "p \"xxxx\"\n", out: `("xxxx" string)`},
{in: "si\n", out: "sample.gno:14"},
{in: "s\ns\n", out: `=> 14: var global = "test"`},
{in: "s\n\n", out: "=> 16: type T struct {"},
{in: "s\n\n", out: "=> 33: num := 5"},
{in: "foo", out: "command not available: foo"},
{in: "\n\n", out: "dbg> "},
{in: "#\n", out: "dbg> "},
Expand Down
14 changes: 6 additions & 8 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,30 +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)))
}
}

if fs != nil {
for _, d := range ds {
setLoc(fs, gd.Pos(), d)
}
}

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:3: constant definition loop with b
// main/files/const9.gno:5: constant definition loop with b

0 comments on commit eaab6e1

Please sign in to comment.