Skip to content

Commit

Permalink
locationless bool crash
Browse files Browse the repository at this point in the history
Summary:
We use BoolT.t in various places. When these are part of errors, their
locationlessness causes an assertion failure.

Will follow up with a more thorough audit of the locationless Primitive
type constructor `t` (also available on NumT, StrT, ...).

Ref #3147

Reviewed By: samwgoldman

Differential Revision: D4490639

fbshipit-source-id: 23f6531e24acf0bd7f8f36fbe9defd5876736ee4
  • Loading branch information
avikchaudhuri authored and facebook-github-bot committed Jan 31, 2017
1 parent 558fbe2 commit e1a2c0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/typing/statement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4401,6 +4401,7 @@ and predicates_of_condition cx e = Ast.(Expression.(

(* inspect a typeof equality test *)
let typeof_test loc sense arg typename str_loc =
let bool = BoolT.at loc in
match refinable_lvalue arg with
| Some name, t ->
let pred = match typename with
Expand All @@ -4413,12 +4414,12 @@ and predicates_of_condition cx e = Ast.(Expression.(
| _ -> None
in
begin match pred with
| Some pred -> result BoolT.t name t pred sense
| Some pred -> result bool name t pred sense
| None ->
Flow_js.add_output cx Flow_error.(EInvalidTypeof (str_loc, typename));
empty_result (BoolT.at loc)
empty_result bool
end
| None, _ -> empty_result (BoolT.at loc)
| None, _ -> empty_result bool
in

let sentinel_prop_test loc ~sense ~strict expr val_t =
Expand Down Expand Up @@ -4635,7 +4636,7 @@ and predicates_of_condition cx e = Ast.(Expression.(
eq_test loc ~sense:false ~strict:true left right

(* Array.isArray(expr) *)
| _, Call {
| loc, Call {
Call.callee = callee_loc, Member {
Member._object = (_, Identifier (_, "Array") as o);
property = Member.PropertyIdentifier (prop_loc, "isArray");
Expand All @@ -4654,12 +4655,13 @@ and predicates_of_condition cx e = Ast.(Expression.(
Flow.flow cx (obj_t, GetPropT (reason, Named (prop_reason, "isArray"), t))
) in
Hashtbl.replace (Context.type_table cx) prop_loc fn_t;
let bool = BoolT.at loc in

match refinable_lvalue arg with
| Some name, t ->
result BoolT.t name t ArrP true
result bool name t ArrP true
| None, _ ->
empty_result BoolT.t
empty_result bool
)

(* test1 && test2 *)
Expand Down
5 changes: 3 additions & 2 deletions tests/predicates-declared/predicates-declared.exp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ sanity-pred-with-body.js:6

sanity-return-type.js:3
3: declare function f2(x: mixed): string %checks(Array.isArray(x));
^^^^^^ string. This type is incompatible with
boolean
^^^^^^^^^^^^^^^^ boolean. This type is incompatible with
3: declare function f2(x: mixed): string %checks(Array.isArray(x));
^^^^^^ string


Found 9 errors

0 comments on commit e1a2c0b

Please sign in to comment.