Skip to content

Commit

Permalink
XXX: Should this be added or not? constraints for param and var
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleidea committed May 5, 2024
1 parent b2b281b commit 7868096
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lang/ast/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9993,7 +9993,23 @@ func (obj *ExprVar) Infer() (*types.Type, []*interfaces.UnificationInvariant, er

// This child call to Infer is an exception to the "Infer must not call
// Infer" rule, because we really want the indirection in this case.
return expr.Infer()
//return expr.Infer()
// XXX XXX XXX: Should we add the obj ptr for this case too?

typ, invariants, err := expr.Infer()
if err != nil {
return nil, nil, err
}

// This adds the obj ptr, so it's seen as an expr that we need to solve.
invar := &interfaces.UnificationInvariant{
Expr: obj,
Expect: typ,
Actual: typ,
}
invariants = append(invariants, invar)

return typ, invariants, nil

// XXX: alternate equivalent version below...

Expand Down Expand Up @@ -10231,6 +10247,8 @@ func (obj *ExprParam) Type() (*types.Type, error) {
// never call another Infer. This Infer returns a quasi-equivalent to my ExprAny
// invariant idea.
func (obj *ExprParam) Infer() (*types.Type, []*interfaces.UnificationInvariant, error) {
invariants := []*interfaces.UnificationInvariant{}

// We know this has to be something, but we don't know what. Return
// anything, just like my ExprAny invariant would have.
typ := obj.Typ
Expand All @@ -10241,7 +10259,15 @@ func (obj *ExprParam) Infer() (*types.Type, []*interfaces.UnificationInvariant,
}
}

return typ, []*interfaces.UnificationInvariant{}, nil
// This adds the obj ptr, so it's seen as an expr that we need to solve.
invar := &interfaces.UnificationInvariant{
Expr: obj,
Expect: typ,
Actual: typ,
}
invariants = append(invariants, invar)

return typ, invariants, nil
}

// Check is checking that the input type is equal to the object that Check is
Expand Down

0 comments on commit 7868096

Please sign in to comment.