If the ast.Files passed to ast.NewPackage includes built in types such as int it returns an error e.g.file1.go:5:6: undeclared name: intIs there a way to prevent that?
Playground example: https://play.golang.org/p/Yg30TTzoLHPMy goal is to take multiple files, resolve inter file dependencies e.g. a type referencing another type in a different file and process the resulting ast.Files. So if there is a better way to achieve this I'm all ears.
--RegardsSteve
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAHEMsqbJoJxuo3c-mofMtzXXJhYCzV2skW2ZB3ZPY6WtA8%2BxHw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAHEMsqavYgUqPOBo6zB5SsizVB39JO9vNUePnecDN-664e0NUQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAHEMsqYMSBUfuOUvptv6UrvBFTwFxjOhJZ5sMN-omOx5ESL5hw%40mail.gmail.com
I converted my code to x/tools/go/packages and while it did solve the problem it's VERY slow in comparison.I have a set of 21 tests operating on a single package which has at most two very basic types, no imports and using go/parser they take 0.011s but with go/packages that increases to 3.548s a 300x slow down.I'm setting a basic mode: packages.NeedName | packages.NeedSyntaxThe package.Load call takes ~220ms whereas ast.NewPackage only takes 2.7µs.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAHEMsqYMSBUfuOUvptv6UrvBFTwFxjOhJZ5sMN-omOx5ESL5hw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d570a7ce-a780-46d8-a323-f9c26a6c2561n%40googlegroups.com.
This is an example of code resulting in ~200ms.This was measured on a laptop with i7-7700HQ under WSL2, so that could be a contributing factor.package mypkg
type MyType struct {
String string
}
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6aaa7c3a-7ef5-47ea-9f29-75443a4599b6n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAHEMsqaQ9%3Dia2MXrVEXt--Qk3Nrx1UXK2JYU0D2BxBcZX%2B5mxw%40mail.gmail