Skip to content

Missed return statement in generated code #222

Closed
@maratori

Description

Bug description

Wire generates broken code. It generates function body without return statement.

To Reproduce

Run wire with following file

// +build wireinject

package storage

import "github.com/google/wire"

type MyInterface interface {
	Method()
}

type MyImplementation struct{}

func (MyImplementation) Method() {}

func XXX(MyImplementation) MyInterface {
	wire.Build(wire.Bind(new(MyInterface), new(MyImplementation)))
	return nil
}

It will generate following file

// Code generated by Wire. DO NOT EDIT.

//go:generate wire
//+build !wireinject

package storage

// Injectors from missed_return.go:

func XXX(myImplementation MyImplementation) MyInterface {

}

// missed_return.go:

type MyInterface interface {
	Method()
}

type MyImplementation struct{}

func (MyImplementation) Method() {}

Expected behavior

Wire should generate following file

//+build !wireinject

package storage

// Injectors from missed_return.go:

func XXX(myImplementation MyImplementation) MyInterface {
	return myImplementation
}

// missed_return.go:

type MyInterface interface {
	Method()
}

type MyImplementation struct{}

func (MyImplementation) Method() {}

Version

github.com/google/wire v0.3.0
go version go1.13 darwin/amd64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions