Simplify removes duplicate type parameters
(p []*TypeParameter)
| 63 | |
| 64 | // Simplify removes duplicate type parameters |
| 65 | func Simplify(p []*TypeParameter) ([]*TypeParameter, error) { |
| 66 | params := []*TypeParameter{} |
| 67 | set := make(map[string]bool) |
| 68 | for _, tp := range p { |
| 69 | ref := tp.Name.Ref() |
| 70 | if _, ok := set[ref]; !ok { |
| 71 | params = append(params, tp) |
| 72 | set[ref] = true |
| 73 | |
| 74 | if union, ok := tp.Type.(*UnionType); ok { |
| 75 | simplifyUnionLiterals(union) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | return params, nil |
| 80 | } |
| 81 | |
| 82 | func simplifyUnionLiterals(union *UnionType) *UnionType { |
| 83 | types := []ExpressionType{} |
no test coverage detected
searching dependent graphs…