You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.
$ cd$GOPATH/src/path/to/my/project
$ gostub Service
$ echo$?
0
$ go build ./service_stubs/service_stub.go
# command-line-arguments
service_stubs/service_stub.go:128:5: cannot use new(ServiceStub) (type *ServiceStub) as type service.Service in assignment:
*ServiceStub does not implement service.Service (wrong typefor GetSession method)
have GetSession(context.Context, string) (*mgo.Session, error)
want GetSession(context.Context, string) (*model.Session, error)
The problem seems that the current LocatorContext implementation (see resolution/context.go) does not take into account the package name when computing possible import paths for non-local non-aliased locations:
The fix I've used is to make sure that the import location ends with the package that is being looked for:
diff --git a/resolution/context.go b/resolution/context.go
index ffd5af3..d75b6f5 100644
--- a/resolution/context.go+++ b/resolution/context.go@@ -58,7 +58,7 @@ func (c *LocatorContext) CandidateLocations(alias string) []string {
if location, found := c.AliasedLocation(alias); found {
return []string{location}
}
- return c.NonLocalNonAliasedLocations()+ return c.NonLocalNonAliasedLocations(alias)
}
func (c *LocatorContext) LocalLocations() []string {
@@ -71,10 +71,10 @@ func (c *LocatorContext) LocalLocations() []string {
return result
}
-func (c *LocatorContext) NonLocalNonAliasedLocations() []string {+func (c *LocatorContext) NonLocalNonAliasedLocations(alias string) []string {
result := []string{}
for _, imp := range c.imports {
- if imp.Alias == "" {+ if imp.Alias == "" && strings.HasSuffix(imp.Location, alias) {
result = append(result, imp.Location)
}
}
I'm not sure whether this won't brake any other scenarios, but unfortunately I don't have much time to spend digging it right now, so I'll go with that fix. Here's what happens after applying it:
$ gostub Service
Stub 'ServiceStub' successfully created in 'service_stubs'.
$ go build ./service_stubs/service_stub.go
$ echo $?
0
I'll not be able to share the code that reproduces the issues as-is, but if you'd like I can create a minimal scenario that reproduces the problem, so its added to the acceptance test suite (which are still passing with the fix applied).
The text was updated successfully, but these errors were encountered:
What I'm doing:
The problem seems that the current
LocatorContext
implementation (seeresolution/context.go
) does not take into account the package name when computing possible import paths for non-local non-aliased locations:The fix I've used is to make sure that the import location ends with the package that is being looked for:
I'm not sure whether this won't brake any other scenarios, but unfortunately I don't have much time to spend digging it right now, so I'll go with that fix. Here's what happens after applying it:
I'll not be able to share the code that reproduces the issues as-is, but if you'd like I can create a minimal scenario that reproduces the problem, so its added to the acceptance test suite (which are still passing with the fix applied).
The text was updated successfully, but these errors were encountered: