Jelajahi Sumber

[typer] delay check_method unification further

Simon Krajewski 5 tahun lalu
induk
melakukan
72e61e05db
2 mengubah file dengan 21 tambahan dan 14 penghapusan
  1. 1 1
      src/typing/fieldAccess.ml
  2. 20 13
      src/typing/typeloadFields.ml

+ 1 - 1
src/typing/fieldAccess.ml

@@ -106,7 +106,7 @@ let resolve_accessor fa mode = match fa.fa_field.cf_kind with
 						in
 						AccessorFound (forward cf_acc new_host)
 					with Not_found ->
-						AccessorAnon
+						if has_class_flag c CExtern then AccessorAnon else AccessorNotFound
 					end
 				| FHAbstract(a,tl,c) ->
 					begin try

+ 20 - 13
src/typing/typeloadFields.ml

@@ -1332,20 +1332,27 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 						), p))
 			in
 			let t2, f2 = get_overload overloads in
-			(match f2.cf_kind with
-				| Method MethMacro ->
-					display_error ctx (f2.cf_name ^ ": Macro methods cannot be used as property accessor") p;
-					display_error ctx (compl_msg (f2.cf_name ^ ": Accessor method is here")) f2.cf_pos;
-				| _ -> ());
-			unify_raise ctx t2 t f2.cf_pos;
-			if (fctx.is_abstract_member && not (has_class_field_flag f2 CfImpl)) || (has_class_field_flag f2 CfImpl && not (fctx.is_abstract_member)) then
-				display_error ctx "Mixing abstract implementation and static properties/accessors is not allowed" f2.cf_pos;
-			f2.cf_meta <- List.fold_left (fun acc ((m,_,_) as meta) -> match m with
-				| Meta.Deprecated -> meta :: acc
-				| _ -> acc
-			) f2.cf_meta f.cff_meta;
+			(* Now that we know there is a field, we have to delay the actual unification even further. The reason is that unification could resolve
+			   TLazy, which would then cause field typing before we're done with our PConnectField pass. This could cause interface fields to not
+			   be generated in time. *)
+			delay ctx PForce (fun () ->
+				try
+					(match f2.cf_kind with
+						| Method MethMacro ->
+							display_error ctx (f2.cf_name ^ ": Macro methods cannot be used as property accessor") p;
+							display_error ctx (compl_msg (f2.cf_name ^ ": Accessor method is here")) f2.cf_pos;
+						| _ -> ());
+					unify_raise ctx t2 t f2.cf_pos;
+					if (fctx.is_abstract_member && not (has_class_field_flag f2 CfImpl)) || (has_class_field_flag f2 CfImpl && not (fctx.is_abstract_member)) then
+						display_error ctx "Mixing abstract implementation and static properties/accessors is not allowed" f2.cf_pos;
+					f2.cf_meta <- List.fold_left (fun acc ((m,_,_) as meta) -> match m with
+						| Meta.Deprecated -> meta :: acc
+						| _ -> acc
+					) f2.cf_meta f.cff_meta;
+				with Error (Unify l,p) ->
+					raise (Error (Stack (Custom ("In method " ^ m ^ " required by property " ^ name),Unify l),p))
+			)
 		with
-			| Error (Unify l,p) -> raise (Error (Stack (Custom ("In method " ^ m ^ " required by property " ^ name),Unify l),p))
 			| Not_found ->
 				let generate_field () =
 					let cf = mk_field m t p null_pos in