-
Notifications
You must be signed in to change notification settings - Fork 47
fix: Result generation for map, slice, pointer when targeting other package #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
From taking a look at the // File: human.go
// Package full name is github.com/vburenin/ifacemaker/example/mypackage
package mypackage
import (
"fmt"
)
type Food struct {
name string
}
func (f *Food) Name() string {
return f.name
}
type Human struct {
}
func (h *Human) Eat(food *Food) {
fmt.Printf("Eating %s...\n", food.Name())
} If you run the following command: ifacemaker -f human.go -m "github.com/vburenin/ifacemaker/example/mypackage" -s Human -i IHuman -p otherpackage -o ihuman.go You will get the following: // Code generated by ifacemaker; DO NOT EDIT.
package otherpackage
import (
. "github.com/vburenin/ifacemaker/example/mypackage"
)
// IHuman ...
type IHuman interface {
Eat(food *Food)
} While not documented in the When using this PR to generate the example above, we can then omit the ifacemaker -f human.go -s Human -i IHuman -p otherpackage -o ihuman.go // Code generated by ifacemaker; DO NOT EDIT.
package otherpackage
import "github.com/vburenin/ifacemaker/example/mypackage"
// IHuman ...
type IHuman interface {
Eat(food *mypackage.Food)
} If everything looks fine so far for the PR, I think all we need is to add a unit test for this functionality. What are your thoughts on this @gaby ? Also, this PR assumes that #65 was merged. Maybe we could merge #72 first into the |
@grivera64 Can you come up with a unit-test for this? |
Using the following command line where
persister
contains files generated by sqlc, the latest version in master generates invalid code for results that are references, e.g. map, slice, and pointers.This PR aims to fix that — which appear to be that the original fix for #12 was incomplete, and this PR assumes PR #65 has been committed.
ifacemaker -f ./persister/*.go -s Queries -i DataStoreQueries -p app -o ./app/query.iface.go
Here is the test code I wrote against:
Without the PR it generates this (and some newlines I removed), which fails to compile in Go:
With the PR, it generates this, also minus newlines, which does compile in Go: