|
@@ -1715,8 +1715,13 @@ let init_class ctx c p context_init herits fields =
|
|
let check_cast e =
|
|
let check_cast e =
|
|
(* insert cast to keep explicit field type (issue #1901) *)
|
|
(* insert cast to keep explicit field type (issue #1901) *)
|
|
if not (type_iseq e.etype cf.cf_type)
|
|
if not (type_iseq e.etype cf.cf_type)
|
|
- then mk (TCast(e,None)) cf.cf_type e.epos
|
|
|
|
- else e
|
|
|
|
|
|
+ then begin match e.eexpr,follow cf.cf_type with
|
|
|
|
+ | TConst (TInt i),TAbstract({a_path=[],"Float"},_) ->
|
|
|
|
+ (* turn int constant to float constant if expected type is float *)
|
|
|
|
+ {e with eexpr = TConst (TFloat (Int32.to_string i))}
|
|
|
|
+ | _ ->
|
|
|
|
+ mk (TCast(e,None)) cf.cf_type e.epos
|
|
|
|
+ end else e
|
|
in
|
|
in
|
|
let r = exc_protect ctx (fun r ->
|
|
let r = exc_protect ctx (fun r ->
|
|
(* type constant init fields (issue #1956) *)
|
|
(* type constant init fields (issue #1956) *)
|