Skip to content

Commit

Permalink
support narrowing in a form true = ...
Browse files Browse the repository at this point in the history
Summary: - supporting `true = SomeExpression` the same ways as `SomeExpression orelse throw(...)` (aka ?EQWALIZER_ASSERT)

Reviewed By: VLanvin

Differential Revision: D59059904

fbshipit-source-id: d4f52a25c1585e73e33aafc1fefb0c31ac9e915d
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed Jun 26, 2024
1 parent b20de90 commit 376cb4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 4 additions & 0 deletions eqwalizer/src/main/scala/com/whatsapp/eqwalizer/tc/Elab.scala
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ final class Elab(pipelineContext: PipelineContext) {
check.checkExpr(l, gradualFunType, env1)
val (patTy, patEnv) = elabPat.elabPat(mPat, gradualFunType, env)
(patTy, patEnv)
case Match(Pats.PatAtom("true"), mExp) if Filters.asTest(mExp).isDefined =>
val test = Filters.asTest(mExp).get
val env1 = elabGuard.elabGuards(List(Guard(List(test))), env)(checkRedundancy = true)
(AtomLitType("true"), env1)
case Match(mPat, mExp) =>
val (ty, env1) = elabExpr(mExp, env)
val (patTy, patEnv) = elabPat.elabPat(mPat, ty, env1)
Expand Down
10 changes: 2 additions & 8 deletions eqwalizer/test_projects/check/src/type_asserts.erl.check
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ scope_neg(A) -> | ERROR |
-spec assert7( | |
string() | binary() | |
) -> binary(). | |
assert7(Input) -> | ERROR |
assert7(Input) -> | OK |
true = is_binary(Input), | |
Input. | | Input.
| | Expression has type: string() | binary()
| | Context expected type: binary()
| |
| | string() | binary() is not compatible with binary()
| | because
| | string() is not compatible with binary()
Input. | |

0 comments on commit 376cb4e

Please sign in to comment.