Skip to content

Commit

Permalink
gen: skip over constructors with unsupported params for non-chain case
Browse files Browse the repository at this point in the history
  • Loading branch information
thepudds committed Jan 3, 2022
1 parent b49a6ef commit 140027f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion gen/genfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,17 @@ func emitIndependentWrappers(pkgPath string, pkgFuncs *pkg, wrapperPkgName strin
for _, function := range pkgFuncs.functions {
var constructors []mod.Func
if options.insertConstructors {
constructors = pkgFuncs.constructors
for _, constructor := range pkgFuncs.constructors {
// Skip over any candidate constructors with unsupported params.
ctorInputParams := params(constructor.TypesFunc)
support, _ := checkParamSupport(ctorInputParams)
if support == noSupport {
continue
}
constructors = append(constructors, constructor)
}
}

err := emitIndependentWrapper(emit, function, constructors, options.qualifyAll)
if err != nil && firstErr == nil {
firstErr = err
Expand Down Expand Up @@ -666,6 +675,23 @@ func receiver(f *types.Func) *types.Named {
return n
}

// params expects a *types.Func that is type *types.Signature,
// and returns a []*types.Var for the parameters.
// This does not include the receiver for a method.
// params returns nil if f is not type *types.Signature.
func params(f *types.Func) []*types.Var {
wrappedSig, ok := f.Type().(*types.Signature)
if !ok {
return nil
}
var inputParams []*types.Var
for i := 0; i < wrappedSig.Params().Len(); i++ {
v := wrappedSig.Params().At(i)
inputParams = append(inputParams, v)
}
return inputParams
}

// constructorResult expects a *types.Func that is type *types.Signature,
// and returns the *types.Named for the first returned result. It allows
// a single return result or two returned results if the second is of type error.
Expand Down

0 comments on commit 140027f

Please sign in to comment.