Skip to content

Commit 3ab8273

Browse files
committed
add CfAbstractConstructor
1 parent 63d547f commit 3ab8273

File tree

7 files changed

+14
-10
lines changed

7 files changed

+14
-10
lines changed

src/core/tType.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,11 @@ type flag_tclass_field =
511511
| CfUsed (* Marker for DCE *)
512512
| CfMaybeUsed (* Marker for DCE *)
513513
| CfNoLookup (* Field cannot be accessed by-name. *)
514+
| CfAbstractConstructor
514515

515516
(* Order has to match declaration for printing*)
516517
let flag_tclass_field_names = [
517-
"CfPublic";"CfStatic";"CfExtern";"CfFinal";"CfModifiesThis";"CfOverride";"CfAbstract";"CfOverload";"CfImpl";"CfEnum";"CfGeneric";"CfDefault";"CfPostProcessed";"CfUsed";"CfMaybeUsed";"CfNoLookup"
518+
"CfPublic";"CfStatic";"CfExtern";"CfFinal";"CfModifiesThis";"CfOverride";"CfAbstract";"CfOverload";"CfImpl";"CfEnum";"CfGeneric";"CfDefault";"CfPostProcessed";"CfUsed";"CfMaybeUsed";"CfNoLookup";"CfAbstractConstructor"
518519
]
519520

520521
type flag_tenum =

src/optimization/inline.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ let inline_default_config cf t =
232232
let inline_config cls_opt cf call_args return_type =
233233
match cls_opt with
234234
| Some ({cl_kind = KAbstractImpl _}) when has_class_field_flag cf CfImpl ->
235-
let t = if cf.cf_name = "_hx_new" then
235+
let t = if has_class_field_flag cf CfAbstractConstructor then
236236
return_type
237237
else if call_args = [] then
238238
raise_typing_error "Invalid abstract implementation function" cf.cf_pos
@@ -580,7 +580,7 @@ class inline_state ctx ethis params cf f p = object(self)
580580
(match follow ethis.etype with
581581
| TAnon a -> (match !(a.a_status) with
582582
| ClassStatics {cl_kind = KAbstractImpl a } when has_class_field_flag cf CfImpl ->
583-
if cf.cf_name <> "_hx_new" then begin
583+
if not (has_class_field_flag cf CfAbstractConstructor) then begin
584584
(* the first argument must unify with a_this for abstract implementation functions *)
585585
let tb = (TFun(("",false,map_type a.a_this) :: (List.tl tl),tret)) in
586586
unify_raise mt tb p

src/typing/callUnification.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ let unify_field_call ctx fa el_typed el p inline =
232232
cfl,Some c,false,TClass.get_map_function c tl,(fun t -> t)
233233
| FHAbstract(a,tl,c) ->
234234
let map = apply_params a.a_params tl in
235-
let tmap = if fa.fa_field.cf_name = "_hx_new" (* TODO: BAD BAD BAD BAD *) then (fun t -> t) else (fun t -> map a.a_this) in
235+
let tmap = if has_class_field_flag fa.fa_field CfAbstractConstructor then (fun t -> t) else (fun t -> map a.a_this) in
236236
expand_overloads fa.fa_field,Some c,true,map,tmap
237237
in
238238
let is_forced_inline = is_forced_inline co fa.fa_field in

src/typing/calls.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let make_call ctx e params t ?(force_inline=false) p =
5454
(match cl, ctx.c.curclass.cl_kind, params with
5555
| Some c, KAbstractImpl _, { eexpr = TLocal { v_meta = v_meta } } :: _ when c == ctx.c.curclass ->
5656
if
57-
f.cf_name <> "_hx_new"
57+
not (has_class_field_flag f CfAbstractConstructor)
5858
&& has_meta Meta.This v_meta
5959
&& has_class_field_flag f CfModifiesThis
6060
then

src/typing/typeloadFields.ml

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type field_init_ctx = {
5454
is_abstract : bool;
5555
is_macro : bool;
5656
is_abstract_member : bool;
57+
is_abstract_constructor : bool;
5758
is_display_field : bool;
5859
is_field_debug : bool;
5960
is_generic : bool;
@@ -529,6 +530,7 @@ let create_field_context ctx cctx cff is_display_file display_modifier =
529530
is_field_debug = cctx.is_class_debug || Meta.has (Meta.Custom ":debug.typeload") cff.cff_meta;
530531
display_modifier = display_modifier;
531532
is_abstract_member = is_abstract_member;
533+
is_abstract_constructor = is_abstract_member && fst cff.cff_name = "_hx_new";
532534
is_generic = Meta.has Meta.Generic cff.cff_meta;
533535
field_kind = field_kind;
534536
do_bind = (((not ((has_class_flag c CExtern) || !is_extern) || is_inline) && not is_abstract && not (has_class_flag c CInterface)) || field_kind = CfrInit);
@@ -631,7 +633,7 @@ let check_field_display ctx fctx c cf =
631633
let scope, cf = match c.cl_kind with
632634
| KAbstractImpl _ ->
633635
if has_class_field_flag cf CfImpl then
634-
(if cf.cf_name = "_hx_new" then
636+
(if fctx.is_abstract_constructor then
635637
CFSConstructor, {cf with cf_name = "new"}
636638
else
637639
CFSMember, cf)
@@ -1087,7 +1089,7 @@ let check_abstract (ctx,cctx,fctx) a c cf fd t ret p =
10871089
| _ -> ();
10881090
in
10891091
List.iter check_meta cf.cf_meta;
1090-
if cf.cf_name = "_hx_new" && Meta.has Meta.MultiType a.a_meta then fctx.do_bind <- false;
1092+
if fctx.is_abstract_constructor && Meta.has Meta.MultiType a.a_meta then fctx.do_bind <- false;
10911093
if fd.f_expr = None then begin
10921094
if fctx.is_inline then missing_expression ctx.com fctx "Inline functions must have an expression" cf.cf_pos;
10931095
if fd.f_type = None then raise_typing_error ("Functions without expressions must have an explicit return type") cf.cf_pos;
@@ -1160,7 +1162,7 @@ let setup_args_ret ctx cctx fctx name fd p =
11601162
maybe_use_property_type fd.f_type (fun () -> match Lazy.force mk with MKGetter | MKSetter -> true | _ -> false) def
11611163
end in
11621164
let abstract_this = match cctx.abstract with
1163-
| Some a when fctx.is_abstract_member && name <> "_hx_new" (* TODO: this sucks *) && not fctx.is_macro ->
1165+
| Some a when fctx.is_abstract_member && not fctx.is_abstract_constructor && not fctx.is_macro ->
11641166
Some a.a_this
11651167
| _ ->
11661168
None
@@ -1271,6 +1273,7 @@ let create_method (ctx,cctx,fctx) c f cf fd p =
12711273
add_class_field_flag cf CfAbstract;
12721274
end;
12731275
if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
1276+
if fctx.is_abstract_constructor then add_class_field_flag cf CfAbstractConstructor;
12741277
if fctx.is_generic then add_class_field_flag cf CfGeneric;
12751278
begin match fctx.default with
12761279
| Some p ->

src/typing/typer.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ and type_array_comprehension ctx e with_type p =
14791479
]) v.v_type p
14801480

14811481
and type_return ?(implicit=false) ctx e with_type p =
1482-
let is_abstract_ctor = ctx.e.curfun = FunMemberAbstract && ctx.f.curfield.cf_name = "_hx_new" in
1482+
let is_abstract_ctor = ctx.e.curfun = FunMemberAbstract && has_class_field_flag ctx.f.curfield CfAbstractConstructor in
14831483
match e with
14841484
| None when is_abstract_ctor ->
14851485
let e_cast = mk (TCast(get_this ctx p,None)) ctx.e.ret p in

src/typing/typerBase.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ let assign_to_this_is_allowed ctx =
188188
| KAbstractImpl _ ->
189189
(match ctx.f.curfield.cf_kind with
190190
| Method MethInline -> true
191-
| Method _ when ctx.f.curfield.cf_name = "_hx_new" -> true
191+
| Method _ when has_class_field_flag ctx.f.curfield CfAbstractConstructor -> true
192192
| _ -> false
193193
)
194194
| _ -> false

0 commit comments

Comments
 (0)