Drop args- and this-related facts after ? call

This commit is contained in:
Nigel Tao committed 2020-11-05 14:49:47 +11:00
1 parent b3cc3c53ad
commit 2dfe222681
3 files changed
+19 -12

No files matched your search

+15 -8
View File
@@ -195,6 +195,14 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
return o, nil
}
func updateFactsForSuspension(x *a.Expr) (*a.Expr, error) {
if x.Mentions(exprArgs) || x.Mentions(exprThis) {
return nil, nil
}
// TODO: drop any facts involving ptr-typed local variables?
return x, nil
}
func (q *checker) bcheckBlock(block []*a.Node) error {
unreachable := false
for _, o := range block {
@@ -213,16 +221,9 @@ func (q *checker) bcheckBlock(block []*a.Node) error {
// No-op.
case a.KRet:
if o.AsRet().Keyword() == t.IDYield {
// Drop any facts involving args or this.
if err := q.facts.update(func(x *a.Expr) (*a.Expr, error) {
if x.Mentions(exprArgs) || x.Mentions(exprThis) {
return nil, nil
}
return x, nil
}); err != nil {
if err := q.facts.update(updateFactsForSuspension); err != nil {
return err
}
// TODO: drop any facts involving ptr-typed local variables?
continue
}
}
@@ -423,6 +424,12 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
return err
}
if rhs.Effect().Coroutine() && (op != t.IDEqQuestion) {
if err := q.facts.update(updateFactsForSuspension); err != nil {
return err
}
}
if lhs == nil {
return nil
}