Can not update generated file after I use it. [chicken and egg problem]
bronze1man opened this issue · comments
This is a very good code generate library!
here is my code
package xxx
const (
LogName_HttpMeta_Req = `HttpMeta_Req`
LogName_HttpMeta_Resp = `HttpMeta_Resp`
)
type LogItem struct {
LogName string
logUnion_TemplateUnion
}
type logUnion_Template struct {
HttpMeta_Req LogItem_HttpMeta_Req
HttpMeta_Resp LogItem_HttpMeta_Resp
}
type LogItem_HttpMeta_Req struct{
Method string
Url string
RemoteAddr string
IsWebsocket bool
}
type LogItem_HttpMeta_Resp struct {
ReqMethod string
ReqUrl string
ReqRemoteAddr string
ReqIsWebsocket bool
RespStatusCode int
}
- Then I have get the bug:
xxxx/log.go:11:2: undeclared name: logUnion_TemplateUnion
exit status 1
I know it is a problem from golang.org/x/tools/go/packages
/ go/types
.
I had fix this kind problem before.
I had implemented a go code parser and type parser(do not use go/ast , go/types).This library can skip all type not exist problem.
But the privated code generate library costs a lot of time to make it skip some golang new grammar after golang version update like type assertion
or type generic
.It may be good to have a open source library.
I will rewrite this library with my private code generate library. If you have some ideas to fix this problem with open source library, please let me know.
I know I can use parameter of pkg to solve this problem, But if you use a lot of code generate in your code, you will find it is hard to solve this kind of chicken and egg problem
It seems like if I ignore the error, then everything is still fine, so I have disabled the error, and it will only be shown if -warn
is passed. Hopefully that should fix the issue.
Thanks, it works.
I just try this myself. And you did it the same way.
I will try golang.org/x/tools/go/packages
in my library.