Skip to content

Commit

Permalink
Removed hard-coded .length case
Browse files Browse the repository at this point in the history
Enable type checker to correctly type non-standard length properties.
Fixes issue facebook#131.
  • Loading branch information
commonlisp committed Jan 21, 2015
1 parent 0de91ac commit 5483abd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,6 @@ let rec flow cx (l,u) trace =
| (_,
(GetT(_,"toLocaleString",_) | SetT(_,"toLocaleString",_))) -> ()

| ((ObjT _ | ArrT _), GetT(reason_op,"length",tout)) ->
unit_flow cx (NumT.why reason_op, tout)

| ((ObjT _ | ArrT _),
(SetT(_,"length",_) | MethodT(_,"length",_,_,_,_))) -> ()

Expand Down
2 changes: 2 additions & 0 deletions tests/misc/F.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function fn2(x) { return x.length * 4; }
fn2({length: 'hi'});
6 changes: 5 additions & 1 deletion tests/misc/misc.exp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ E.js:8:6,10: boolean
This type is incompatible with
E.js:4:14,19: number

Found 3 errors
F.js:2:14,17: string
This type is incompatible with
F.js:1:26,37: number

Found 4 errors

0 comments on commit 5483abd

Please sign in to comment.