MCPcopy
hub / github.com/google/mangle / refineNegative

Method refineNegative

analysis/infercontext.go:77–101  ·  view source on GitHub ↗

refineNegative uses negative information to refine an existing binding

(v ast.Variable, tpe ast.BaseTerm)

Source from the content-addressed store, hash-verified

75
76// refineNegative uses negative information to refine an existing binding
77func (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
103func (s *inferState) asMap() map[ast.Variable]ast.BaseTerm {
104 m := make(map[ast.Variable]ast.BaseTerm, len(s.varTpe))

Callers 1

Calls 4

IsUnionTypeExpressionFunction · 0.92
RemoveFromUnionTypeFunction · 0.92
FindMethod · 0.80
EqualsMethod · 0.65

Tested by

no test coverage detected