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

Method addOrRefine

analysis/infercontext.go:55–74  ·  view source on GitHub ↗

addOrRefine either adds a binding or intersects type for an existing one.

(v ast.Variable, tpe ast.BaseTerm)

Source from the content-addressed store, hash-verified

53
54// addOrRefine either adds a binding or intersects type for an existing one.
55func (s *inferState) addOrRefine(v ast.Variable, tpe ast.BaseTerm) error {
56 if tpe.Equals(symbols.EmptyType) {
57 return fmt.Errorf("variable %v has empty type", v)
58 }
59 if v.Symbol == "_" {
60 return nil
61 }
62 i := s.usedVars.Find(v)
63 if i == -1 {
64 s.usedVars = s.usedVars.Extend([]ast.Variable{v})
65 s.varTpe = append(s.varTpe, tpe)
66 return nil
67 }
68 tpe = symbols.LowerBound(nil /*TODO*/, []ast.BaseTerm{s.varTpe[i], tpe})
69 if tpe.Equals(symbols.EmptyType) {
70 return fmt.Errorf("variable %v cannot have both %v and %v", v, s.varTpe[i], tpe)
71 }
72 s.varTpe[i] = tpe
73 return nil
74}
75
76// refineNegative uses negative information to refine an existing binding
77func (s *inferState) refineNegative(v ast.Variable, tpe ast.BaseTerm) error {

Callers 2

Calls 4

LowerBoundFunction · 0.92
FindMethod · 0.80
EqualsMethod · 0.65
ExtendMethod · 0.45

Tested by

no test coverage detected