Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

The alias defined using the type keyword is not used during code generation; instead, the original type is used. #415

@Ifuhao

Description

@Ifuhao

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions