Skip to content

Commit 10b0bc2

Browse files
committed
fix #4426, apply bs.inlne to float too
1 parent 698e6bf commit 10b0bc2

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

jscomp/syntax/ast_literal.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ let type_int64 =
134134
Ast_helper.Typ.mk
135135
(Ptyp_constr ({ txt = Lident "int64"; loc = Location.none}, []))
136136

137+
let type_float =
138+
Ast_helper.Typ.mk
139+
(Ptyp_constr ({ txt = Lident "float"; loc = Location.none}, []))
140+
137141
let type_any ?loc () =
138142
match loc with
139143
| None -> No_loc.type_any

jscomp/syntax/ast_literal.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ val type_string : core_type_lit
6262
val type_bool : core_type_lit
6363
val type_int : core_type_lit
6464
val type_int64 : Parsetree.core_type
65+
val type_float : Parsetree.core_type
6566
val type_any : core_type_lit
6667

6768
val pat_unit : pattern_lit

jscomp/syntax/bs_builtin_ppx.ml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
259259
value_desc with
260260
pval_prim = External_ffi_types.inline_int64_primitive s;
261261
pval_attributes = [];
262-
} }
262+
} }
263+
| Pexp_constant (Pconst_float(s,None)) ->
264+
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
265+
{sigi with psig_desc = Psig_value {
266+
value_desc with
267+
pval_prim = External_ffi_types.inline_float_primitive s;
268+
pval_attributes = [];
269+
} }
263270
| Pexp_construct ({txt = Lident ("true" | "false" as txt)}, None)
264271
->
265272
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
@@ -338,6 +345,16 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
338345
pval_attributes = [];
339346
pval_prim = External_ffi_types.inline_int64_primitive s
340347
} }
348+
| Pexp_constant(Pconst_float (s, None))
349+
->
350+
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
351+
{str with pstr_desc = Pstr_primitive {
352+
pval_name = pval_name ;
353+
pval_type = Ast_literal.type_float;
354+
pval_loc = pvb_loc;
355+
pval_attributes = [];
356+
pval_prim = External_ffi_types.inline_float_primitive s
357+
} }
341358
| Pexp_construct ({txt = Lident ("true" | "false" as txt) },None) ->
342359
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
343360
{str with pstr_desc = Pstr_primitive {

jscomp/syntax/external_ffi_types.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ let inline_int64_primitive (i : int64) : string list =
316316
(Const_int64 i))
317317
]
318318

319+
let inline_float_primitive (i : string) : string list =
320+
["";
321+
to_string
322+
(Ffi_inline_const (Const_float i))
323+
]
319324
let rec ffi_bs_aux acc (params : External_arg_spec.params) =
320325
match params with
321326
| {arg_type = Nothing; arg_label = Arg_empty}

jscomp/syntax/external_ffi_types.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ val inline_int64_primitive :
141141
int64 ->
142142
string list
143143

144+
val inline_float_primitive :
145+
string -> string list
146+
144147
val ffi_bs:
145148
External_arg_spec.params ->
146149
return_wrapper ->

0 commit comments

Comments
 (0)