commonConstantType returns the most constrained type which is mutually resolvable between a set of provided constants. The function takes a slice of Exprs and indexes, but expects all the indexed Exprs to wrap a Constant. The reason it does no take a slice of Constants instead is to avoid forcing c
(vals []Expr, idxs []int)
| 377 | // Exprs to wrap a Constant. The reason it does no take a slice of Constants |
| 378 | // instead is to avoid forcing callers to allocate separate slices of Constant. |
| 379 | func commonConstantType(vals []Expr, idxs []int) (*types.T, bool) { |
| 380 | var candidates []*types.T |
| 381 | |
| 382 | for _, i := range idxs { |
| 383 | availableTypes := vals[i].(Constant).DesirableTypes() |
| 384 | if candidates == nil { |
| 385 | candidates = availableTypes |
| 386 | } else { |
| 387 | candidates = intersectTypeSlices(candidates, availableTypes) |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | if len(candidates) > 0 { |
| 392 | return candidates[0], true |
| 393 | } |
| 394 | return nil, false |
| 395 | } |
| 396 | |
| 397 | // StrVal represents a constant string value. |
| 398 | type StrVal struct { |
no test coverage detected
searching dependent graphs…