refineNegative uses negative information to refine an existing binding
(v ast.Variable, tpe ast.BaseTerm)
| 75 | |
| 76 | // refineNegative uses negative information to refine an existing binding |
| 77 | func (s *inferState) refineNegative(v ast.Variable, tpe ast.BaseTerm) error { |
| 78 | if v.Symbol == "_" { |
| 79 | return nil |
| 80 | } |
| 81 | i := s.usedVars.Find(v) |
| 82 | if i == -1 { |
| 83 | return nil |
| 84 | } |
| 85 | existing := s.varTpe[i] |
| 86 | if existing.Equals(tpe) { |
| 87 | return fmt.Errorf("variable %v bounded by %v cannot be refined with negative %v", v, s.varTpe[i], tpe) |
| 88 | } |
| 89 | if !symbols.IsUnionTypeExpression(existing) { |
| 90 | return nil |
| 91 | } |
| 92 | newTpe, err := symbols.RemoveFromUnionType(tpe, existing) |
| 93 | if err != nil { |
| 94 | return err |
| 95 | } |
| 96 | if newTpe.Equals(symbols.EmptyType) { |
| 97 | return fmt.Errorf("variable %v bounded by %v cannot be refined with negative %v", v, s.varTpe[i], tpe) |
| 98 | } |
| 99 | s.varTpe[i] = newTpe |
| 100 | return nil |
| 101 | } |
| 102 | |
| 103 | func (s *inferState) asMap() map[ast.Variable]ast.BaseTerm { |
| 104 | m := make(map[ast.Variable]ast.BaseTerm, len(s.varTpe)) |
no test coverage detected