internal/wire: fix crash when giving wire.Struct a bad first argument (#220)
This commit is contained in:
@@ -805,7 +805,7 @@ func processStructProvider(fset *token.FileSet, info *types.Info, call *ast.Call
|
|||||||
st, ok := structPtr.Elem().Underlying().(*types.Struct)
|
st, ok := structPtr.Elem().Underlying().(*types.Struct)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, notePosition(fset.Position(call.Pos()),
|
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)
|
stExpr := call.Args[0].(*ast.CallExpr)
|
||||||
|
|||||||
27
internal/wire/testdata/StructNotAStruct/foo/foo.go
vendored
Normal file
27
internal/wire/testdata/StructNotAStruct/foo/foo.go
vendored
Normal 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
|
||||||
|
}
|
||||||
26
internal/wire/testdata/StructNotAStruct/foo/wire.go
vendored
Normal file
26
internal/wire/testdata/StructNotAStruct/foo/wire.go
vendored
Normal 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 ""
|
||||||
|
}
|
||||||
1
internal/wire/testdata/StructNotAStruct/pkg
vendored
Normal file
1
internal/wire/testdata/StructNotAStruct/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
example.com/foo
|
||||||
1
internal/wire/testdata/StructNotAStruct/want/wire_errs.txt
vendored
Normal file
1
internal/wire/testdata/StructNotAStruct/want/wire_errs.txt
vendored
Normal 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
|
||||||
Reference in New Issue
Block a user