Open Min8Yue opened 2 weeks ago
x go run -toolexec decorator main.go
command-line-arguments
./main.go:22: misplaced compiler directive command-line-arguments: open /var/folders/3g/8n4r6n1d5b1fz6phh1rpfmx80000gp/T/go-build3187272546/b001/pkg.a: no such file or directory
这个错误通常是在使用 go-decorator
之前有编译过此代码,go 的旧编译缓存被引用导致的。
可以尝试使用 -a
标志强制重新编译一次来解决。在这个 case 中,可以使用命令:
$ go run -toolexec decorator -a main.go
This error is usually caused by compiling the code before using go-decorator
, and the old compilation cache of go is being referenced.
Try forcing a recompile with the -a
flag. In this case, you can use the command:
$ go run -toolexec decorator -a main.go
相同的源码,还是无法通过编译. 你可以尝试复现吗?
$ go run -toolexec decorator -a main.go
# command-line-arguments
./main.go:22: misplaced compiler directive
command-line-arguments: open /var/folders/3g/8n4r6n1d5b1fz6phh1rpfmx80000gp/T/go-build2815434048/b001/_pkg_.a: no such file or directory
相同的源码,还是无法通过编译. 你可以尝试复现吗?
$ go run -toolexec decorator -a main.go # command-line-arguments ./main.go:22: misplaced compiler directive command-line-arguments: open /var/folders/3g/8n4r6n1d5b1fz6phh1rpfmx80000gp/T/go-build2815434048/b001/_pkg_.a: no such file or directory
看报错似乎不是 decorator 的问题。使用 go build -toolexec decorator
编译试试看。
I tried to use nested annotations, a compilation error was reported, and the error message was not enough for me to locate the problem. When I changed the location of the function in the source code, the problem disappeared. Source Code
output
Enviroment go version go1.22.5 darwin/arm64