From 85b20d2d0535bed8a174b4db0e600e2e575c5a0e Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Mon, 1 Aug 2016 16:28:04 -0400 Subject: [PATCH] fix int option bug --- jscomp/syntax/ast_external_attributes.ml | 11 ++++++++++- jscomp/test/infer_type_test.js | 19 +++++++++++++++++++ jscomp/test/infer_type_test.ml | 21 ++++++++++++++++++++- jscomp/test/infer_type_test.mli | 9 ++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/jscomp/syntax/ast_external_attributes.ml b/jscomp/syntax/ast_external_attributes.ml index 28290794d9..40f184a3a5 100644 --- a/jscomp/syntax/ast_external_attributes.ml +++ b/jscomp/syntax/ast_external_attributes.ml @@ -442,7 +442,16 @@ let handle_attributes | (_, ty), `Label s -> (s , [], ty) :: acc | (_, ty), `Optional s - -> (s, [], Ast_comb.to_js_undefined_type loc ty) :: acc + -> + begin match (ty : Ast_core_type.t) with + | {ptyp_desc = + Ptyp_constr({txt = + Ldot (Lident "*predef*", "option") }, + [ty])} + -> + (s, [], Ast_comb.to_js_undefined_type loc ty) :: acc + | _ -> assert false + end | (_, _), `Empty -> acc ) arg_types_ty arg_labels []) Closed in Ast_core_type.replace_result type_annotation result diff --git a/jscomp/test/infer_type_test.js b/jscomp/test/infer_type_test.js index 6254d907ea..10b42d9661 100644 --- a/jscomp/test/infer_type_test.js +++ b/jscomp/test/infer_type_test.js @@ -8,5 +8,24 @@ var hh = { hh.width; +var v = { + hi: 32, + lo: 3 +}; + +var vv = { + hi: 3, + lo: 3, + width: 3 +}; + +var u = v.hi; + +var uu = v.width; + exports.hh = hh; +exports.v = v; +exports.vv = vv; +exports.u = u; +exports.uu = uu; /* hh Not a pure module */ diff --git a/jscomp/test/infer_type_test.ml b/jscomp/test/infer_type_test.ml index 1bebc6e578..d530fcffa0 100644 --- a/jscomp/test/infer_type_test.ml +++ b/jscomp/test/infer_type_test.ml @@ -4,10 +4,29 @@ external mk_config : hi:int -> lo:int -> ?width:int -> unit -> _ = "" [@@bs.obj] -type hh = < hi : int; lo : int; width : int option Js.undefined > Js.t +type hh = < hi : int; lo : int; width : int Js.undefined > Js.t let hh = mk_config ~hi:30 ~lo:20 () (* let v = hh##widt *) let v = hh##width +external + config : + hi:int -> + lo:int -> + ?width:int -> + unit -> _ = "" [@@bs.obj] + +let v = config ~hi:32 ~lo:3 () + +let vv = config ~lo:3 ~width:3 ~hi:3 () + +let u = v##hi +(* val u: int type*) +let uu = v##width +(* val uu : int Js.undefined *) +(* compile error +let uu = v##xx +*) + diff --git a/jscomp/test/infer_type_test.mli b/jscomp/test/infer_type_test.mli index e0b08db743..c660e4509f 100644 --- a/jscomp/test/infer_type_test.mli +++ b/jscomp/test/infer_type_test.mli @@ -2,5 +2,12 @@ external mk_config : hi:int -> lo:int -> ?width:int -> unit -> _ = "" [@@bs.obj] -type hh = < hi : int; lo : int; width : int option Js.undefined > Js.t +type hh = < hi : int; lo : int; width : int Js.undefined > Js.t val hh : hh + +val v : < hi : int; lo : int; width : int Js.undefined > Js.t + +val vv : < hi : int; lo : int; width : int Js.undefined > Js.t + +val u : int +val uu : int Js.undefined