Skip to content

Commit

Permalink
add a new patch set to re-produce the comment golang#416 in cl610059
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuschen committed Sep 7, 2024
1 parent 0c0e815 commit 06c6220
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions go/ssa/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ func (s *sanity) checkReferrerList(v Value) {

// checkFunctionParams checks whether the function parameters match the function signature,
// it reports an error if the function is not built.
//
// this change tries to reproduce the issue mentioned here:
// https://go-review.googlesource.com/c/tools/+/610059/comment/8539d464_5744937f/
//
// when we match types between Function.Signature.RecvTypeParams() and Params,
// it fails if the function is a synthetic function.
//
// there're two errors:
// 1. Error: function (*p.Pointer[[]int]).Load[[]int]: expect type *p.Pointer[[]int] in signature but got type T in param 0
// 2. Error: function (p.A).Foo: function has 0 parameters in signature but has 1 after building
// you can run 'gotip test ./go/ssa' to reproduce it
func (s *sanity) checkFunctionParams(fn *Function) {
signature := fn.Signature
params := fn.Params
Expand All @@ -418,26 +429,15 @@ func (s *sanity) checkFunctionParams(fn *Function) {
return
}

// startSigParams is the start of signature.Params() within params.
startSigParams := 0
if signature.Recv() != nil {
startSigParams = 1
}

if startSigParams+signature.Params().Len() != len(params) {
sigAllParams := signature.RecvTypeParams()
if sigAllParams.Len() != len(params) {
s.errorf("function has %d parameters in signature but has %d after building",
startSigParams+signature.Params().Len(), len(params))
sigAllParams.Len(), len(params))
return
}

for i, param := range params {
var sigType types.Type
si := i - startSigParams
if si < 0 {
sigType = signature.Recv().Type()
} else {
sigType = signature.Params().At(si).Type()
}
sigType := sigAllParams.At(i).Obj().Type()

if !types.Identical(sigType, param.Type()) {
s.errorf("expect type %s in signature but got type %s in param %d", param.Type(), sigType, i)
Expand Down

0 comments on commit 06c6220

Please sign in to comment.