Browse Source

don't show "defined in this class" message when class is module-statics for now (see #9466)

this needs more investigation, because we might want still show something but with correct position and phrasing, when there's an actual call from a macro
Dan Korostelev 5 years ago
parent
commit
7eba712d68
2 changed files with 8 additions and 1 deletions
  1. 6 0
      src/core/tFunctions.ml
  2. 2 1
      src/typing/typeloadFields.ml

+ 6 - 0
src/core/tFunctions.ml

@@ -734,6 +734,12 @@ let has_constructor c =
 		true
 	with Not_found -> false
 
+let is_module_statics_class c =
+	match c.cl_kind with KModuleStatics _ -> true | _ -> false
+
+let is_pos_outside_class c p =
+	p.pfile <> c.cl_pos.pfile || p.pmax < c.cl_pos.pmin || p.pmin > c.cl_pos.pmax
+
 let resolve_typedef t =
 	match t with
 	| TClassDecl _ | TEnumDecl _ | TAbstractDecl _ -> t

+ 2 - 1
src/typing/typeloadFields.ml

@@ -513,7 +513,8 @@ let create_class_context ctx c context_init p =
 		on_error = (fun ctx msg ep ->
 			ctx.com.error msg ep;
 			(* macros expressions might reference other code, let's recall which class we are actually compiling *)
-			if !locate_macro_error && (ep.pfile <> c.cl_pos.pfile || ep.pmax < c.cl_pos.pmin || ep.pmin > c.cl_pos.pmax) then ctx.com.error "Defined in this class" c.cl_pos
+			let open TFunctions in
+			if !locate_macro_error && (is_pos_outside_class c ep) && not (is_module_statics_class c) then ctx.com.error "Defined in this class" c.cl_pos
 		);
 	} in
 	(* a lib type will skip most checks *)