internal/wire: fix crash when giving wire.Struct a bad first argument (#220)

This commit is contained in:
Ross Light
2019-11-11 11:06:03 -08:00
committed by shantuo
parent 0d3b2ebd4a
commit a5347c86bc
5 changed files with 56 additions and 1 deletions

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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 ""
}

View File

@@ -0,0 +1 @@
example.com/foo

View File

@@ -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