From 05f3d65dbddf927bfde4bee91c4b5b448caba71c Mon Sep 17 00:00:00 2001 From: George Kuan Date: Sat, 17 Jan 2015 21:42:01 -0800 Subject: [PATCH] Removed hard-coded .length cases Enable type checker to correctly type non-standard length properties. Fixes issue #131. --- src/typing/flow_js.ml | 6 ------ tests/misc/F.js | 2 ++ tests/misc/G.js | 3 +++ tests/misc/misc.exp | 14 +++++++++++++- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 tests/misc/F.js create mode 100644 tests/misc/G.js diff --git a/src/typing/flow_js.ml b/src/typing/flow_js.ml index 75fef2af199..fcf0d4c67db 100644 --- a/src/typing/flow_js.ml +++ b/src/typing/flow_js.ml @@ -1262,12 +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",_,_,_,_))) -> () - | ((ObjT _ | ArrT _), GetT(reason_op,"constructor",tout)) -> unit_flow cx (AnyT.why reason_op, tout) diff --git a/tests/misc/F.js b/tests/misc/F.js new file mode 100644 index 00000000000..7ed391e44ec --- /dev/null +++ b/tests/misc/F.js @@ -0,0 +1,2 @@ +function fn2(x) { return x.length * 4; } +fn2({length: 'hi'}); diff --git a/tests/misc/G.js b/tests/misc/G.js new file mode 100644 index 00000000000..3d855be654f --- /dev/null +++ b/tests/misc/G.js @@ -0,0 +1,3 @@ +var a = { length: "duck" }; +a.length = 123; +a.length(); diff --git a/tests/misc/misc.exp b/tests/misc/misc.exp index a739c4e101e..12a4fd8f76f 100644 --- a/tests/misc/misc.exp +++ b/tests/misc/misc.exp @@ -11,4 +11,16 @@ 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 + +G.js:2:12,14: number +This type is incompatible with + G.js:1:19,24: string + +G.js:3:1,10: call of method length +Function cannot be called on + G.js:1:19,24: string + +Found 6 errors