英文:
GoLang - types from different scopes
问题
如果你遇到了如下错误:
interface conversion: interface {} is *purchase.User, not *purchase.User (types from different scopes)
看起来你发送的类型是正确的,因为错误消息中的期望类型和实际类型完全相同。
英文:
If you are getting an error like:
interface conversion: interface {} is *purchase.User, not *purchase.User (types from different scopes)
It appears that you are sending the correct type since the expected and actual type in the error message are exactly the same.
答案1
得分: 1
你可能在另一个包(purchase2)中创建了另一种指向*purchase.User的类型,并且这是你的方法正在寻找的类型,但你却发送了(purchase.User)。
例如:
在purchase
包中:
type User struct {
firstName string
lastName string
}
在purchase2
包中:
import purchase
type User purchase.User
请检查你所引用的类型。
英文:
You may have created another type pointing to the *purchase.User in another package (purchase2) and that is the type your method is looking into receiving but you are sending (purchase.User)
For example:
in purchase
package
type User struct {
firstName string
lastName string
}
in purchase2
package
import purchase
type User purchase.User
Check which type are you referring to.
答案2
得分: 0
这可能是由于你以两个不同的导入路径导入了同一个包,导致了这个问题。除非在特殊情况下(如AST代码重写、非标准的依赖管理等),否则很少见到这种情况。
如果你正在使用不同的路径导入同一个包,那么很有可能你正在做一些非常错误的事情。停止这样做吧
英文:
Alternate cause for this: you have somehow imported the package twice, with two different import paths. This is unlikely to be seen except in unusual circumstances (AST code rewriters, non-standard vendoring, etc).
If you are importing the same package with different paths, there is a very good chance that you're doing something very wrong. Stop it
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论