fix: Result generation for map, slice, pointer when targeting other package #66
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.goYou 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
persistercontains 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.goHere 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: