@@ -2600,7 +2600,6 @@ module rec Expr : sig
26002600 as in `<<MyAttr()>> class C` (note that attributes are classes) *)
26012601 val new_object :
26022602 expected :ExpectedTy .t option ->
2603- check_parent :bool ->
26042603 check_not_abstract :bool ->
26052604 is_using_clause :bool ->
26062605 is_attribute :bool ->
@@ -4602,7 +4601,6 @@ end = struct
46024601 new_object
46034602 ~expected
46044603 ~is_using_clause: ctxt.Context. is_using_clause
4605- ~check_parent: false
46064604 ~check_not_abstract: true
46074605 ~is_attribute: false
46084606 pos
@@ -5240,7 +5238,6 @@ end = struct
52405238
52415239 and new_object
52425240 ~(expected : ExpectedTy.t option )
5243- ~check_parent
52445241 ~check_not_abstract
52455242 ~is_using_clause
52465243 ~is_attribute
@@ -5320,8 +5317,7 @@ end = struct
53205317 end
53215318 in
53225319 if
5323- (not check_parent)
5324- && (not is_using_clause)
5320+ (not is_using_clause)
53255321 && Typing_disposable. is_disposable_class env class_info
53265322 then
53275323 Typing_error_utils. add_typing_error
@@ -5357,8 +5353,6 @@ end = struct
53575353 let (env, cid_ty) = Env. expand_type env cid_ty in
53585354 if is_generic cid_ty then
53595355 (env, cid_ty)
5360- else if check_parent then
5361- (env, c_ty)
53625356 else
53635357 ExprDepTy. make env ~cid: cid_ c_ty
53645358 in
@@ -5494,8 +5488,6 @@ end = struct
54945488 in
54955489 if is_generic stripped_cid_ty then
54965490 (env, cid_ty)
5497- else if check_parent then
5498- (env, ty)
54995491 else
55005492 ExprDepTy. make env ~cid: cid_ ty
55015493 in
@@ -5593,85 +5585,23 @@ end = struct
55935585
55945586 (env, (te, ty))
55955587
5596- and check_parent_construct pos recv_pos env el unpacked_element env_parent =
5597- let check_not_abstract = false in
5598- let ((env, ty_err_opt), env_parent) =
5599- Phase. localize_no_subst env ~ignore_errors: true env_parent
5600- in
5601- Option. iter ~f: (Typing_error_utils. add_typing_error ~env ) ty_err_opt;
5602- let ( env,
5603- _tcid,
5604- _tal,
5605- tel,
5606- typed_unpack_element,
5607- parent,
5608- fty,
5609- should_forget_fakes ) =
5610- new_object
5611- ~expected: None
5612- ~check_parent: true
5613- ~check_not_abstract
5614- ~is_using_clause: false
5615- ~is_attribute: false
5616- pos
5617- env
5618- (() , recv_pos, CIparent )
5619- []
5620- el
5621- unpacked_element
5622- in
5623- (* Not sure why we need to equate these types *)
5624- let (env, e1) =
5625- Type. sub_type
5626- pos
5627- Reason. URnone
5628- env
5629- env_parent
5630- parent
5631- Typing_error.Callback. unify_error
5632- in
5633- let (env, e2) =
5634- Type. sub_type
5635- pos
5636- Reason. URnone
5637- env
5638- parent
5639- env_parent
5640- Typing_error.Callback. unify_error
5641- in
5642- Option. (
5643- iter ~f: (Typing_error_utils. add_typing_error ~env )
5644- @@ merge e1 e2 ~f: Typing_error. both);
5645- ( env,
5646- tel,
5647- typed_unpack_element,
5648- MakeType. void (Reason. witness pos),
5649- parent,
5650- fty,
5651- should_forget_fakes )
5652-
5653- and call_parent_construct pos recv_pos env el unpacked_element =
5588+ (* Check that the parent exists in a parent::__construct call *)
5589+ and check_parent_construct_receiver pos env =
56545590 match Env. get_parent_ty env with
5655- | Some parent ->
5656- check_parent_construct pos recv_pos env el unpacked_element parent
5591+ (* Direct parent, so ok *)
5592+ | Some _parent -> ()
56575593 | None ->
5658- (* continue here *)
5659- let (env, ty) = Env. fresh_type_error env pos in
5660- let should_invalidate_fake_members = true in
5661- let default =
5662- (env, [] , None , ty, ty, ty, should_invalidate_fake_members)
5663- in
56645594 (match Env. get_self_id env with
56655595 | Some self ->
56665596 let open TraitMostConcreteParent in
56675597 (match Env. get_class env self with
5598+ (* Self is a trait, so look at trait's parents *)
56685599 | Decl_entry. Found trait when Ast_defs. is_c_trait (Cls. kind trait) ->
56695600 (match trait_most_concrete_parent trait env with
56705601 | None ->
56715602 Typing_error_utils. add_typing_error
56725603 ~env
5673- Typing_error. (primary @@ Primary. Parent_in_trait pos);
5674- default
5604+ Typing_error. (primary @@ Primary. Parent_in_trait pos)
56755605 | Some NotFound ->
56765606 let trait_reqs =
56775607 Some
@@ -5683,9 +5613,8 @@ end = struct
56835613 Typing_error_utils. add_typing_error
56845614 ~env
56855615 Typing_error. (
5686- primary @@ Primary. Parent_undefined { pos; trait_reqs });
5687- default
5688- | Some (Found (c , parent_ty )) ->
5616+ primary @@ Primary. Parent_undefined { pos; trait_reqs })
5617+ | Some (Found (c , _parent_ty )) ->
56895618 (match Typing_env. get_construct env c with
56905619 | (_ , Inconsistent) ->
56915620 Typing_error_utils. add_typing_error
@@ -5694,29 +5623,13 @@ end = struct
56945623 primary
56955624 @@ Primary. Trait_parent_construct_inconsistent
56965625 { pos; decl_pos = Cls. pos c })
5697- | _ -> () );
5698- check_parent_construct
5699- pos
5700- recv_pos
5701- env
5702- el
5703- unpacked_element
5704- parent_ty)
5705- | Decl_entry. Found _self_tc ->
5706- Typing_error_utils. add_typing_error
5707- ~env
5708- Typing_error. (
5709- primary @@ Primary. Parent_undefined { pos; trait_reqs = None });
5710- default
5711- | Decl_entry. NotYetAvailable
5712- | Decl_entry. DoesNotExist ->
5713- assert false )
5626+ | _ -> () ))
5627+ | _ -> () )
57145628 | None ->
5629+ (* We're not even inside a class *)
57155630 Typing_error_utils. add_typing_error
57165631 ~env
5717- Typing_error. (primary @@ Primary. Parent_outside_class pos);
5718- let (env, ty) = Env. fresh_type_error env pos in
5719- (env, [] , None , ty, ty, ty, should_invalidate_fake_members))
5632+ Typing_error. (primary @@ Primary. Parent_outside_class pos))
57205633
57215634 (* Depending on the kind of expression we are dealing with
57225635 * The typing of call is different.
@@ -6257,37 +6170,16 @@ end = struct
62576170 | _ -> (env, res))
62586171 | _ -> dispatch_class_const env class_id method_id
62596172 end
6260- (* Special function `parent::__construct` *)
6261- | Class_const ((_, pos, CIparent ), ((_, construct) as id))
6262- when String. equal construct SN.Members. __construct ->
6263- let ( env,
6264- tel,
6265- typed_unpack_element,
6266- ty,
6267- pty,
6268- ctor_fty,
6269- should_forget_fakes ) =
6270- call_parent_construct p pos env el unpacked_element
6271- in
6272- let (env, te) =
6273- Typing_helpers. make_simplify_typed_expr
6274- env
6275- fpos
6276- ctor_fty
6277- (Aast. Class_const ((pty, pos, Aast. CIparent ), id))
6278- in
6279- let result =
6280- make_call
6281- env
6282- te
6283- [] (* tal: no type arguments to constructor *)
6284- tel
6285- typed_unpack_element
6286- ty
6287- in
6288- (result, should_forget_fakes)
62896173 (* Calling parent / class method *)
6290- | Class_const (class_id , m ) -> dispatch_class_const env class_id m
6174+ | Class_const (class_id , m ) ->
6175+ let () =
6176+ match (class_id, m) with
6177+ | ((_, pos, CIparent ), (_, construct))
6178+ when String. equal construct SN.Members. __construct ->
6179+ check_parent_construct_receiver pos env
6180+ | _ -> ()
6181+ in
6182+ dispatch_class_const env class_id m
62916183 (* Readonly Expressions do not affect the type, but need to be threaded through when they're part of a call *)
62926184 | ReadonlyExpr r ->
62936185 let env = Env. set_readonly env true in
@@ -11272,7 +11164,6 @@ end = struct
1127211164 let (env, _, _, _, _, _, _, _) =
1127311165 Expr. new_object
1127411166 ~expected: None
11275- ~check_parent: false
1127611167 ~check_not_abstract: false
1127711168 ~is_using_clause: false
1127811169 ~is_attribute: true
0 commit comments