Skip to content

Commit

Permalink
Fix assert node dropping expression
Browse files Browse the repository at this point in the history
Summary: Right now, we drop the expression in assert nodes. This adds it back.

Reviewed By: jamesjwu

Differential Revision: D5555247

fbshipit-source-id: 76771f4ee077a5fee15d82f716aa891466024bda
  • Loading branch information
rameshvarun authored and hhvm-bot committed Aug 15, 2017
1 parent 27e4eec commit 8115170
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hphp/hack/src/typing/typing.ml
Expand Up @@ -1133,8 +1133,9 @@ and expr_
let env, new_ty = ExprDepTy.make env CIstatic ty in
make_result env T.This (new_ty)
| Assert (AE_assert e) ->
let env, te, _ = expr env e in
let env = condition env true e in
make_result env T.Any (Reason.Rwitness p, Tprim Tvoid)
make_result env (T.Assert (T.AE_assert te)) (Reason.Rwitness p, Tprim Tvoid)
| True ->
make_result env T.True (Reason.Rwitness p, Tprim Tbool)
| False ->
Expand Down
16 changes: 16 additions & 0 deletions hphp/hack/test/tast/assert.php
@@ -0,0 +1,16 @@
<?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "hack" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

class A {}

function foo(?A $x): void {
assert($x instanceof A);
}
41 changes: 41 additions & 0 deletions hphp/hack/test/tast/assert.php.exp
@@ -0,0 +1,41 @@
[(AnnotatedAST.Fun
{ AnnotatedAST.f_mode = <opaque>;
f_ret = (Some (<p>, (Hprim Tvoid)));
f_name = (<p>, "\\foo"); f_tparams = [];
f_where_constraints = []; f_variadic = AnnotatedAST.FVnonVariadic;
f_params =
[{ AnnotatedAST.param_hint =
(Some (<p>,
(Hoption
(<p>,
(Happly ((<p>, "\\A"), []))))));
param_is_reference = false; param_is_variadic = false;
param_pos = <p>; param_name = "$x"; param_expr = None
}
];
f_body =
(AnnotatedAST.NamedBody
{ AnnotatedAST.fnb_nast =
[(AnnotatedAST.Expr
((Some void),
(AnnotatedAST.Assert
(AnnotatedAST.AE_assert
((Some bool),
(AnnotatedAST.InstanceOf (
((Some ?\A),
(AnnotatedAST.Lvar (<p>, $x))),
(AnnotatedAST.CI ((<p>, "\\A"), []))
)))))))
];
fnb_unsafe = false });
f_fun_kind = FSync; f_user_attributes = [] });
(AnnotatedAST.Class
{ AnnotatedAST.c_mode = <opaque>; c_final = false; c_is_xhp = false;
c_kind = Cnormal; c_name = (<p>, "\\A");
c_tparams = <opaque>; c_extends = []; c_uses = [];
c_xhp_attr_uses = []; c_xhp_category = []; c_req_extends = [];
c_req_implements = []; c_implements = []; c_consts = [];
c_typeconsts = []; c_static_vars = []; c_vars = [];
c_constructor = None; c_static_methods = []; c_methods = [];
c_user_attributes = []; c_enum = None })
]

0 comments on commit 8115170

Please sign in to comment.