如何配置 Goland IDE,以便*不*对“在此包中重新声明”错误发出警告?

huangapple go评论146阅读模式
英文:

How to configure Goland IDE to *not* warn about "<Symbol> redeclared in this package" error

问题

我正在使用Goland IDE编写各种简单的、实验性的Go程序,以提高我对Go的理解,并进行各种其他练习。

我有一个包含N个不同Go文件的目录,它们都是完全独立的。每个文件都在"main"包中,并且每个文件都有一个main函数。我可以在Goland中独立地调用每个Go文件。

不幸的是,Goland并不认为所有这些"main"文件是独立的,当在两个不同的文件中声明相同的符号时,它会显示错误。有没有办法让Goland不显示这个错误?

我可以通过将每个Go文件放在单独的目录中来解决这个问题,但是对于每个不同的简单、实验性的Go程序来说,这似乎有点过度设计。

英文:

I'm using Goland IDE to write various simple, experimental Go programs to improve my understanding of Go and to do various other exercises.

I have a directory containing N different Go files, that are all completely independent. Each file is in package "main", and each has a main function. I can independently invoke each Go file from within Goland.

Unfortunately, Goland doesn't think that all these "main" files are independent, and it is showing errors when the the same symbol is declared in two different files. Is there any way to stop Goland from displaying this error ?

I could work around the problem by placing each Go file in a separate directory, but it seems an overkill to have a directory for each different simple, experimental Go program.

答案1

得分: 1

Goland在技术上是正确的。同一目录中的所有文件,具有相同的package pkgname语句,属于同一个包。你运行它们时,通过相当于go run myfile.go的方式进行单独文件的编译,这是你在运行它们时没有遇到任何问题的主要原因。

英文:

Goland is technically correct. All files in the same directory, with the same package pkgname statement belong to the same package. The fact that you run them, causing individual file compilation, with the equivalent of go run myfile.go is the main reason you are not seeing any problems when running them.

huangapple
  • 本文由 发表于 2021年12月1日 12:19:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/70179082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定