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

go/parser: ParseDir is not returning error with re-declarations #8031

Closed
gopherbot opened this issue May 19, 2014 · 1 comment
Closed

go/parser: ParseDir is not returning error with re-declarations #8031

gopherbot opened this issue May 19, 2014 · 1 comment

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented May 19, 2014

by raul.san@sent.com:

"go/parser.ParseDir" is not returning an error at parsing files with a keyword
re-declared.
Note: this possible bug also could happens in "parser.ParseFile".

* * *

+ File: foo.go
***
package main

import (
    "go/parser"
    "go/token"
    "log"
)

func main() {
    fset := token.NewFileSet()
    _, err := parser.ParseDir(fset, "data", nil, parser.ParseComments|parser.DeclarationErrors)
    if err != nil {
        log.Fatal(err)
    }
}
***

+ File: data/a.go
***
package main

func Foo() {}
***

+ File: data/b.go
***
package main

func Foo() {}
***

* * *
However, if you try to use the "go tool" build it, it will return such error:

    data$ go build
    ./b.go:3: Foo redeclared in this block
        previous declaration at ./a.go:3

* * *
go version go1.2.1 linux/amd64
@dsymonds
Copy link
Member

@dsymonds dsymonds commented May 20, 2014

Comment 1:

go/parser is not a compiler. It parses Go source code, but that is not sufficient to
determine whether it is completely valid Go source code.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.