Open
Description
You can use go bug
to have a cool, automatically filled out bug template, or
fill out the template below.
Describe the bug
The alias defined using the type
keyword is not used during code generation; instead, the original type is used.
To Reproduce
Let's make some changes to the journey program.
There are 2 packages: main and types
in the package types: there are two go files named message.go and greeter.go
message.go
package types
import "fmt"
type Message interface {
Print()
}
type message struct {
content string
}
type MessageOptions = func(*message) string
func NewMessage(opt MessageOptions) Message {
m := &message{}
opt(m)
return m
}
func (m *message) Print() {
fmt.Println(m.content)
}
greeter.go
package types
type Greeter struct {
message Message
}
func NewGreeter(message Message) Greeter {
return Greeter{message: message}
}
func (g Greeter) Message() Message {
return g.message
}
in the package main, there is only one file named wire.go
wire.go
//go:build wireinject
// +build wireinject
package main
import (
"github.com/google/wire"
"types"
)
func InitController(gen types.MessageOptions) types.Greeter {
wire.Build(types.NewGreeter, types.NewMessage)
return types.Greeter{}
}
Then I ran the wire program to generate wire_gen.go.
wire_gen.go
// Code generated by Wire. DO NOT EDIT.
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject
package main
import (
"cascade/app/test/5/types"
)
// Injectors from wire.go:
func InitController(gen func(*types.message) string) types.Greeter {
message := types.NewMessage(gen)
greeter := types.NewGreeter(message)
return greeter
}
Expected behavior
I expect types.MessageOptions to remain in wire_gen.go, rather than being translated to *func(types.message).
Version
v0.6.0
Additional context
nothing
Metadata
Assignees
Labels
No labels
Activity