Skip to content

Commit

Permalink
fix int option bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed Aug 1, 2016
1 parent 2288af5 commit 85b20d2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
11 changes: 10 additions & 1 deletion jscomp/syntax/ast_external_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions jscomp/test/infer_type_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
21 changes: 20 additions & 1 deletion jscomp/test/infer_type_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
*)

9 changes: 8 additions & 1 deletion jscomp/test/infer_type_test.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 85b20d2

Please sign in to comment.