lang: unification, interfaces: Add a skip invariant

This is a cleaner way of telling the type unifier that we don't want
this particular expression in the solution set at the end.
This commit is contained in:
James Shubin
2023-12-17 21:41:20 -05:00
parent c2bf4ef7d4
commit 7cc231e8b9
3 changed files with 63 additions and 0 deletions

View File

@@ -28,6 +28,8 @@ import (
// Invariant represents a constraint that is described by the Expr's and Stmt's,
// and which is passed into the unification solver to describe what is known by
// the AST.
// XXX: add the extended methods into sub-interfaces since not each invariant
// uses them...
type Invariant interface {
// TODO: should we add any other methods to this type?
fmt.Stringer
@@ -1049,3 +1051,34 @@ func (obj *CallFuncArgsValueInvariant) Possible(partials []Invariant) error {
// XXX: not implemented
return nil // safer to return nil than error
}
// SkipInvariant expresses that a particular expression does must not be part of
// the final solution, and should be skipped. It can be part of the solving
// process though.
type SkipInvariant struct {
Expr Expr
}
// String returns a representation of this invariant.
func (obj *SkipInvariant) String() string {
return fmt.Sprintf("skip(%p)", obj.Expr)
}
// ExprList returns the list of valid expressions in this invariant. It is not
// used for this invariant.
func (obj *SkipInvariant) ExprList() []Expr {
// XXX: not used
return []Expr{obj.Expr}
}
// Matches is not used for this invariant.
func (obj *SkipInvariant) Matches(solved map[Expr]*types.Type) (bool, error) {
// XXX: not used
panic("not used")
}
// Possible is not used for this invariant.
func (obj *SkipInvariant) Possible(partials []Invariant) error {
// XXX: not used
panic("not used")
}