chiaDev
chiaDev

Reputation: 459

GoLang - 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.

Upvotes: 0

Views: 749

Answers (2)

Mark
Mark

Reputation: 1053

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 :P

Upvotes: 0

chiaDev
chiaDev

Reputation: 459

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.

Upvotes: 1

Related Questions