diff --git a/internal/wire/parse.go b/internal/wire/parse.go index 0af96294..d72e171c 100644 --- a/internal/wire/parse.go +++ b/internal/wire/parse.go @@ -805,7 +805,7 @@ func processStructProvider(fset *token.FileSet, info *types.Info, call *ast.Call st, ok := structPtr.Elem().Underlying().(*types.Struct) if !ok { return nil, notePosition(fset.Position(call.Pos()), - fmt.Errorf(firstArgReqFormat, types.TypeString(st, nil))) + fmt.Errorf(firstArgReqFormat, types.TypeString(structPtr, nil))) } stExpr := call.Args[0].(*ast.CallExpr) diff --git a/internal/wire/testdata/StructNotAStruct/foo/foo.go b/internal/wire/testdata/StructNotAStruct/foo/foo.go new file mode 100644 index 00000000..b308ebad --- /dev/null +++ b/internal/wire/testdata/StructNotAStruct/foo/foo.go @@ -0,0 +1,27 @@ +// Copyright 2019 The Wire Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" +) + +func main() { + fmt.Println(inject(A{"Hello"})) +} + +type A struct { + B string +} diff --git a/internal/wire/testdata/StructNotAStruct/foo/wire.go b/internal/wire/testdata/StructNotAStruct/foo/wire.go new file mode 100644 index 00000000..3bea345e --- /dev/null +++ b/internal/wire/testdata/StructNotAStruct/foo/wire.go @@ -0,0 +1,26 @@ +// Copyright 2019 The Wire Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//+build wireinject + +package main + +import ( + "github.com/google/wire" +) + +func inject(a A) string { + wire.Build(wire.Struct(new(*A), "*")) + return "" +} diff --git a/internal/wire/testdata/StructNotAStruct/pkg b/internal/wire/testdata/StructNotAStruct/pkg new file mode 100644 index 00000000..f7a5c8ce --- /dev/null +++ b/internal/wire/testdata/StructNotAStruct/pkg @@ -0,0 +1 @@ +example.com/foo diff --git a/internal/wire/testdata/StructNotAStruct/want/wire_errs.txt b/internal/wire/testdata/StructNotAStruct/want/wire_errs.txt new file mode 100644 index 00000000..e1ada680 --- /dev/null +++ b/internal/wire/testdata/StructNotAStruct/want/wire_errs.txt @@ -0,0 +1 @@ +example.com/foo/wire.go:x:y: first argument to Struct must be a pointer to a named struct; found **example.com/foo.A \ No newline at end of file