Skip to content
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

Missed receiver in generated inject method #371

Open
px3303 opened this issue Aug 24, 2022 · 0 comments · May be fixed by #372
Open

Missed receiver in generated inject method #371

px3303 opened this issue Aug 24, 2022 · 0 comments · May be fixed by #372

Comments

@px3303
Copy link

px3303 commented Aug 24, 2022

What version of Go are you using (go version)?

$ go version
go version go1.17.2 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/simbapeng/Library/Caches/go-build"
GOENV="/Users/simbapeng/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/simbapeng/go/pkg/mod"
GONOPROXY="git.trustasia.cn/*"
GONOSUMDB="git.trustasia.cn/*"
GOOS="darwin"
GOPATH="/Users/simbapeng/go"
GOPRIVATE="git.trustasia.cn/*"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/Cellar/go/1.17.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/simbapeng/Project/gendemo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t0/tw9t0q2j7_z5lvxgdx_4chtm0000gn/T/go-build3502256362=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.17.2 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.17.2
uname -v: Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64
ProductName:	macOS
ProductVersion:	12.5
BuildVersion:	21G72
lldb --version: lldb-1316.0.9.46
Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)

What did you do?

//go:build wireinject
// +build wireinject

package main

import (
	"io"
	"os"

	"github.com/google/wire"
)

type foo struct{}
type bar struct{}

func (foo) injectWriter() io.Writer {
	wire.Build(wire.InterfaceValue(new(io.Writer), os.Stdout))
	return nil
}

func (bar) injectWriter() io.Writer {
	wire.Build(wire.InterfaceValue(new(io.Writer), os.Stderr))
	return nil
}

What did you expect to see?

package main

import (
	"io"
	"os"
)

// Injectors from main.go:

func (foo) injectWriter() io.Writer {
	writer := _wireFileValue
	return writer
}

var (
	_wireFileValue = os.Stdout
)

func (bar) injectWriter() io.Writer {
	writer := _wireOsFileValue
	return writer
}

var (
	_wireOsFileValue = os.Stderr
)

// main.go:

type foo struct{}

type bar struct{}

What did you see instead?

Wire generates broken code. It generates function without receiver.

package main

import (
	"io"
	"os"
)

// Injectors from main.go:

func injectWriter() io.Writer {
	writer := _wireFileValue
	return writer
}

var (
	_wireFileValue = os.Stdout
)

func injectWriter() io.Writer {
	writer := _wireOsFileValue
	return writer
}

var (
	_wireOsFileValue = os.Stderr
)

// main.go:

type foo struct{}

type bar struct{}
px3303 added a commit to px3303/wire that referenced this issue Aug 24, 2022
@px3303 px3303 linked a pull request Aug 24, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant