Go语言是否有自动导出未导出名称的功能?

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

Does Go have a feature to automatically export unexported names?

问题

我正在遇到大量的错误,例如:

> foo.thing未定义(类型Foo没有字段或方法thing,但确实有Thing)

即修复非常简单,只需将foo.thing更改为foo.Thing

在Go中,有没有一种方法可以告诉go build批量进行这些更改?

英文:

I'm getting hundreds of errors like:

> foo.thing undefined (type Foo has no field or method thing, but does have Thing)

i.e. the fix is very simple, just change foo.thing to foo.Thing.

Is there a way in Go to tell go build to just go ahead and make these changes in mass?

答案1

得分: 1

GoLand重构"重命名代码元素"可能是一个不错的方法。

Go语言是否有自动导出未导出名称的功能?

VSCode的重命名符号也可以帮助。

但是Go本身没有这个功能。
有一个积压的功能请求,要求编译错误消息更加准确(问题38965

不是(在这个例子中)

./prog.go:11:7: a.B undefined (type A has no field or method B, but does have b)
./prog.go:12:3: a.s undefined (type A has no field or method s, but does have S)

而是更具指导性的:

./prog.go:11:7: a.B undefined (type A has no field or method B, but does have field b)
./prog.go:12:3: a.s undefined (type A has no field or method s, but does have method S)

CL 232938,2020年5月,仍在等待中。

英文:

The GoLand refactoring "Rename a code element" might be a good approach.

Go语言是否有自动导出未导出名称的功能?

VSCode rename symbol could help too.

But Go itself does not have that.
There is a backlog feature request for the compilation error message to be more precise (issue 38965)

Instead of (in this example)

./prog.go:11:7: a.B undefined (type A has no field or method B, but does have b)
./prog.go:12:3: a.s undefined (type A has no field or method s, but does have S)

Having the more prescriptive:

./prog.go:11:7: a.B undefined (type A has no field or method B, but does have field b)
./prog.go:12:3: a.s undefined (type A has no field or method s, but does have method S)

CL 232938, May 2020, still pending.

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

发表评论

匿名网友

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

确定