(val reflect.Value)
| 183 | } |
| 184 | |
| 185 | func inferFuncType(val reflect.Value) *FuncType { |
| 186 | // Make sure the `interface{}` passed in was indeed a function |
| 187 | ty := val.Type() |
| 188 | if ty.Kind() != reflect.Func { |
| 189 | panic("callback provided must be a `func`") |
| 190 | } |
| 191 | |
| 192 | // infer the parameter types, and `*Caller` type is special in the |
| 193 | // parameters so be sure to case on that as well. |
| 194 | params := make([]*ValType, 0, ty.NumIn()) |
| 195 | var caller *Caller |
| 196 | for i := 0; i < ty.NumIn(); i++ { |
| 197 | paramTy := ty.In(i) |
| 198 | if paramTy != reflect.TypeOf(caller) { |
| 199 | params = append(params, typeToValType(paramTy)) |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // Then infer the result types, where a final `*Trap` result value is |
| 204 | // also special. |
| 205 | results := make([]*ValType, 0, ty.NumOut()) |
| 206 | var trap *Trap |
| 207 | for i := 0; i < ty.NumOut(); i++ { |
| 208 | resultTy := ty.Out(i) |
| 209 | if i == ty.NumOut()-1 && resultTy == reflect.TypeOf(trap) { |
| 210 | continue |
| 211 | } |
| 212 | results = append(results, typeToValType(resultTy)) |
| 213 | } |
| 214 | return NewFuncType(params, results) |
| 215 | } |
| 216 | |
| 217 | func typeToValType(ty reflect.Type) *ValType { |
| 218 | var a int32 |
no test coverage detected
searching dependent graphs…