Skip to content

Commit

Permalink
Swap props to negate tests
Browse files Browse the repository at this point in the history
Summary: `negateGuardProp` is not the correct way to negate a test: since we already have both the positive and the negated prop on hand, reversing the two is enough and correct.

Reviewed By: ilya-klyuchnikov

Differential Revision: D60386301

fbshipit-source-id: a761c205f9c76b7fa2f89f3a4ac21ee451045a98
  • Loading branch information
VLanvin authored and facebook-github-bot committed Jul 29, 2024
1 parent aadbac1 commit a142f4c
Showing 1 changed file with 1 addition and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,7 @@ final class Occurrence(pipelineContext: PipelineContext) {
.map(obj => (Pos(obj, tp), Neg(obj, tp)))
.getOrElse(Unknown, Unknown)
case TestUnOp("not", test) =>
val (p1, p2) = testProps(test, aMap)
(negateGuardProp(p1), negateGuardProp(p2))
testProps(test, aMap).swap
case TestBinOp("and" | "andalso", test1, test2) =>
val (pos1, neg1) = testProps(test1, aMap)
val (pos2, neg2) = testProps(test2, aMap)
Expand All @@ -507,24 +506,6 @@ final class Occurrence(pipelineContext: PipelineContext) {
}
}

private def negateGuardProp(prop: Prop): Prop =
prop match {
case True =>
False
case False =>
True
case Unknown =>
Unknown
case And(props) =>
or(props.map(negateGuardProp))
case Or(props) =>
and(props.map(negateGuardProp))
case Pos(obj, t) =>
Neg(obj, t)
case Neg(obj, t) =>
Pos(obj, t)
}

private def patProps(x: String, path: Path, pat: Pat, env: Env): Option[(Prop, Prop)] = {
pat match {
case PatWild() =>
Expand Down

0 comments on commit a142f4c

Please sign in to comment.