Browse Source

[everywhere] rename error to typing_error

I want to reason about our error handling more easily in order to improve compilation server robustness, but that's hard if everything is just named "error"...
Simon Krajewski 3 years ago
parent
commit
7b622ddd64
42 changed files with 435 additions and 435 deletions
  1. 8 8
      src/context/abstractCast.ml
  2. 2 2
      src/context/purityState.ml
  3. 2 2
      src/core/abstract.ml
  4. 5 5
      src/core/error.ml
  5. 2 2
      src/core/inheritDoc.ml
  6. 7 7
      src/core/texpr.ml
  7. 15 15
      src/filters/exceptions.ml
  8. 7 7
      src/filters/filters.ml
  9. 12 12
      src/generators/genjvm.ml
  10. 15 15
      src/generators/genlua.ml
  11. 1 1
      src/generators/genshared.ml
  12. 5 5
      src/macro/eval/evalContext.ml
  13. 2 2
      src/macro/eval/evalExceptions.ml
  14. 2 2
      src/macro/eval/evalJit.ml
  15. 1 1
      src/optimization/analyzerTexpr.ml
  16. 2 2
      src/optimization/analyzerTexprTransformer.ml
  17. 9 9
      src/optimization/inline.ml
  18. 1 1
      src/optimization/inlineConstructors.ml
  19. 1 1
      src/optimization/optimizer.ml
  20. 1 1
      src/optimization/optimizerTexpr.ml
  21. 7 7
      src/typing/callUnification.ml
  22. 9 9
      src/typing/calls.ml
  23. 1 1
      src/typing/fieldAccess.ml
  24. 7 7
      src/typing/fields.ml
  25. 4 4
      src/typing/finalization.ml
  26. 5 5
      src/typing/forLoop.ml
  27. 3 3
      src/typing/functionArguments.ml
  28. 11 11
      src/typing/generic.ml
  29. 6 6
      src/typing/instanceBuilder.ml
  30. 16 16
      src/typing/macroContext.ml
  31. 5 5
      src/typing/magicTypes.ml
  32. 22 22
      src/typing/matcher.ml
  33. 21 21
      src/typing/operators.ml
  34. 42 42
      src/typing/typeload.ml
  35. 18 18
      src/typing/typeloadCheck.ml
  36. 59 59
      src/typing/typeloadFields.ml
  37. 2 2
      src/typing/typeloadFunction.ml
  38. 32 32
      src/typing/typeloadModule.ml
  39. 3 3
      src/typing/typeloadParse.ml
  40. 48 48
      src/typing/typer.ml
  41. 7 7
      src/typing/typerBase.ml
  42. 7 7
      src/typing/typerDisplay.ml

+ 8 - 8
src/context/abstractCast.ml

@@ -41,7 +41,7 @@ and do_check_cast ctx uctx tleft eright p =
 					raise (Error (Unify l, eright.epos)))
 			| _ -> ()
 		end;
-		if cf == ctx.curfield || rec_stack_memq cf cast_stack then error "Recursive implicit cast" p;
+		if cf == ctx.curfield || rec_stack_memq cf cast_stack then typing_error "Recursive implicit cast" p;
 		rec_stack_loop cast_stack cf f ()
 	in
 	let make (a,tl,(tcf,cf)) =
@@ -162,9 +162,9 @@ let find_array_access ctx a tl e1 e2o p =
 		let s_type = s_type (print_context()) in
 		match e2o with
 		| None ->
-			error (Printf.sprintf "No @:arrayAccess function for %s accepts argument of %s" (s_type (TAbstract(a,tl))) (s_type e1.etype)) p
+			typing_error (Printf.sprintf "No @:arrayAccess function for %s accepts argument of %s" (s_type (TAbstract(a,tl))) (s_type e1.etype)) p
 		| Some e2 ->
-			error (Printf.sprintf "No @:arrayAccess function for %s accepts arguments of %s and %s" (s_type (TAbstract(a,tl))) (s_type e1.etype) (s_type e2.etype)) p
+			typing_error (Printf.sprintf "No @:arrayAccess function for %s accepts arguments of %s and %s" (s_type (TAbstract(a,tl))) (s_type e1.etype) (s_type e2.etype)) p
 
 let find_multitype_specialization com a pl p =
 	let uctx = default_unification_context in
@@ -180,7 +180,7 @@ let find_multitype_specialization com a pl p =
 					stack := t :: !stack;
 					match follow t with
 					| TAbstract ({ a_path = [],"Class" },_) ->
-						error (Printf.sprintf "Cannot use %s as key type to Map because Class<T> is not comparable on JavaScript" (s_type (print_context()) t1)) p;
+						typing_error (Printf.sprintf "Cannot use %s as key type to Map because Class<T> is not comparable on JavaScript" (s_type (print_context()) t1)) p;
 					| TEnum(en,tl) ->
 						PMap.iter (fun _ ef -> ignore(loop ef.ef_type)) en.e_constrs;
 						Type.map loop t
@@ -197,16 +197,16 @@ let find_multitype_specialization com a pl p =
 			if List.exists (fun t -> has_mono t) definitive_types then begin
 				let at = apply_params a.a_params pl a.a_this in
 				let st = s_type (print_context()) at in
-				error ("Type parameters of multi type abstracts must be known (for " ^ st ^ ")") p
+				typing_error ("Type parameters of multi type abstracts must be known (for " ^ st ^ ")") p
 			end;
 			t
 		with Not_found ->
 			let at = apply_params a.a_params pl a.a_this in
 			let st = s_type (print_context()) at in
 			if has_mono at then
-				error ("Type parameters of multi type abstracts must be known (for " ^ st ^ ")") p
+				typing_error ("Type parameters of multi type abstracts must be known (for " ^ st ^ ")") p
 			else
-				error ("Abstract " ^ (s_type_path a.a_path) ^ " has no @:to function that accepts " ^ st) p;
+				typing_error ("Abstract " ^ (s_type_path a.a_path) ^ " has no @:to function that accepts " ^ st) p;
 	in
 	cf, follow m
 
@@ -218,7 +218,7 @@ let handle_abstract_casts ctx e =
 					let's construct the underlying type. *)
 				match Abstract.get_underlying_type a pl with
 				| TInst(c,tl) as t -> {e with eexpr = TNew(c,tl,el); etype = t}
-				| _ -> error ("Cannot construct " ^ (s_type (print_context()) (TAbstract(a,pl)))) e.epos
+				| _ -> typing_error ("Cannot construct " ^ (s_type (print_context()) (TAbstract(a,pl)))) e.epos
 			end else begin
 				(* a TNew of an abstract implementation is only generated if it is a multi type abstract *)
 				let cf,m = find_multitype_specialization ctx.com a pl e.epos in

+ 2 - 2
src/context/purityState.ml

@@ -29,12 +29,12 @@ let get_purity_from_meta meta =
 			| "true" | "inferredPure" -> Pure
 			| "false" -> Impure
 			| "expect" -> ExpectPure p
-			| _ -> error ("Unsupported purity value " ^ s ^ ", expected true or false") p
+			| _ -> typing_error ("Unsupported purity value " ^ s ^ ", expected true or false") p
 			end
 		| (_,[],_) ->
 			Pure
 		| (_,_,p) ->
-			error "Unsupported purity value" p
+			typing_error "Unsupported purity value" p
 		end
 	with Not_found ->
 		MaybePure

+ 2 - 2
src/core/abstract.ml

@@ -83,7 +83,7 @@ let rec find_multitype_params a pl =
 				| EMeta((Meta.Custom ":followWithAbstracts",_,_),e1) ->
 					loop follow_with_abstracts e1;
 				| _ ->
-					error "Type parameter expected" (pos e)
+					typing_error "Type parameter expected" (pos e)
 			in
 			loop (fun t -> t) e
 		) el;
@@ -124,7 +124,7 @@ and get_underlying_type ?(return_first=false) a pl =
 				if rec_stack_exists (fast_eq t) underlying_type_stack then begin
 					let pctx = print_context() in
 					let s = String.concat " -> " (List.map (fun t -> s_type pctx t) (List.rev (t :: underlying_type_stack.rec_stack))) in
-					error ("Abstract chain detected: " ^ s) a.a_pos
+					typing_error ("Abstract chain detected: " ^ s) a.a_pos
 				end;
 				get_underlying_type a tl
 			| _ ->

+ 5 - 5
src/core/error.ml

@@ -288,13 +288,13 @@ and s_call_error = function
 	| Could_not_unify err -> error_msg err
 	| Cannot_skip_non_nullable s -> "Cannot skip non-nullable argument " ^ s
 
-let error msg p = raise (Error (Custom msg,p))
+let typing_error msg p = raise (Error (Custom msg,p))
 
-let raise_error err p = raise (Error(err,p))
+let raise_typing_error err p = raise (Error(err,p))
 
 let error_require r p =
 	if r = "" then
-		error "This field is not available with the current compilation flags" p
+		typing_error "This field is not available with the current compilation flags" p
 	else
 	let r = if r = "sys" then
 		"a system platform (php,neko,cpp,etc.)"
@@ -305,6 +305,6 @@ let error_require r p =
 	with _ ->
 		"'" ^ r ^ "' to be enabled"
 	in
-	error ("Accessing this field requires " ^ r) p
+	typing_error ("Accessing this field requires " ^ r) p
 
-let invalid_assign p = error "Invalid assign" p
+let invalid_assign p = typing_error "Invalid assign" p

+ 2 - 2
src/core/inheritDoc.ml

@@ -8,7 +8,7 @@ let expr_to_target e =
 		match e with
 		| EConst (Ident s) when s <> "" -> [s]
 		| EField (e,s) -> s :: loop e
-		| _ -> Error.error "Invalid target expression for @:inheritDoc" p
+		| _ -> Error.typing_error "Invalid target expression for @:inheritDoc" p
 	in
 	match loop e with
 	| sub_name :: type_name :: pack when not (is_lower_ident type_name) ->
@@ -16,7 +16,7 @@ let expr_to_target e =
 	| type_name :: pack ->
 		(List.rev pack, type_name), None
 	| [] ->
-		Error.error "Invalid target path for @:inheritDoc" (snd e)
+		Error.typing_error "Invalid target path for @:inheritDoc" (snd e)
 
 let rec get_constructor c =
 	match c.cl_constructor, c.cl_super with

+ 7 - 7
src/core/texpr.ml

@@ -505,7 +505,7 @@ module Builder = struct
 		| TFloat f -> mk (TConst (TFloat f)) basic.tfloat p
 		| TBool b -> mk (TConst (TBool b)) basic.tbool p
 		| TNull -> mk (TConst TNull) (basic.tnull (mk_mono())) p
-		| _ -> error "Unsupported constant" p
+		| _ -> typing_error "Unsupported constant" p
 
 	let field e name t p =
 		let f =
@@ -569,7 +569,7 @@ let rec constructor_side_effects e =
 let type_constant basic c p =
 	match c with
 	| Int s ->
-		if String.length s > 10 && String.sub s 0 2 = "0x" then error "Invalid hexadecimal integer" p;
+		if String.length s > 10 && String.sub s 0 2 = "0x" then typing_error "Invalid hexadecimal integer" p;
 		(try mk (TConst (TInt (Int32.of_string s))) basic.tint p
 		with _ -> mk (TConst (TFloat s)) basic.tfloat p)
 	| Float f -> mk (TConst (TFloat f)) basic.tfloat p
@@ -577,8 +577,8 @@ let type_constant basic c p =
 	| Ident "true" -> mk (TConst (TBool true)) basic.tbool p
 	| Ident "false" -> mk (TConst (TBool false)) basic.tbool p
 	| Ident "null" -> mk (TConst TNull) (basic.tnull (mk_mono())) p
-	| Ident t -> error ("Invalid constant :  " ^ t) p
-	| Regexp _ -> error "Invalid constant" p
+	| Ident t -> typing_error ("Invalid constant :  " ^ t) p
+	| Regexp _ -> typing_error "Invalid constant" p
 
 let rec type_constant_value basic (e,p) =
 	match e with
@@ -591,7 +591,7 @@ let rec type_constant_value basic (e,p) =
 	| EArrayDecl el ->
 		mk (TArrayDecl (List.map (type_constant_value basic) el)) (basic.tarray t_dynamic) p
 	| _ ->
-		error "Constant value expected" p
+		typing_error "Constant value expected" p
 
 let is_constant_value basic e =
 	try (ignore (type_constant_value basic e); true) with Error (Custom _,_) -> false
@@ -600,7 +600,7 @@ let for_remap basic v e1 e2 p =
 	let v' = alloc_var v.v_kind v.v_name e1.etype e1.epos in
 	let ev' = mk (TLocal v') e1.etype e1.epos in
 	let t1 = (Abstract.follow_with_abstracts e1.etype) in
-	let ehasnext = mk (TField(ev',try quick_field t1 "hasNext" with Not_found -> error (s_type (print_context()) t1 ^ "has no field hasNext()") p)) (tfun [] basic.tbool) e1.epos in
+	let ehasnext = mk (TField(ev',try quick_field t1 "hasNext" with Not_found -> typing_error (s_type (print_context()) t1 ^ "has no field hasNext()") p)) (tfun [] basic.tbool) e1.epos in
 	let ehasnext = mk (TCall(ehasnext,[])) basic.tbool ehasnext.epos in
 	let enext = mk (TField(ev',quick_field t1 "next")) (tfun [] v.v_type) e1.epos in
 	let enext = mk (TCall(enext,[])) v.v_type e1.epos in
@@ -635,7 +635,7 @@ let build_metadata api t =
 	let make_meta_field ml =
 		let h = Hashtbl.create 0 in
 		mk (TObjectDecl (List.map (fun (f,el,p) ->
-			if Hashtbl.mem h f then error ("Duplicate metadata '" ^ f ^ "'") p;
+			if Hashtbl.mem h f then typing_error ("Duplicate metadata '" ^ f ^ "'") p;
 			Hashtbl.add h f ();
 			(f,null_pos,NoQuotes), mk (match el with [] -> TConst TNull | _ -> TArrayDecl (List.map (type_constant_value api) el)) (api.tarray t_dynamic) p
 		) ml)) t_dynamic p

+ 15 - 15
src/filters/exceptions.ml

@@ -31,12 +31,12 @@ let is_dynamic t =
 let haxe_exception_static_call ctx method_name args p =
 	let method_field =
 		try PMap.find method_name ctx.haxe_exception_class.cl_statics
-		with Not_found -> error ("haxe.Exception has no field " ^ method_name) p
+		with Not_found -> typing_error ("haxe.Exception has no field " ^ method_name) p
 	in
 	let return_type =
 		match follow method_field.cf_type with
 		| TFun(_,t) -> t
-		| _ -> error ("haxe.Exception." ^ method_name ^ " is not a function and cannot be called") p
+		| _ -> typing_error ("haxe.Exception." ^ method_name ^ " is not a function and cannot be called") p
 	in
 	add_dependency ctx.typer.curclass.cl_module ctx.haxe_exception_class.cl_module;
 	make_static_call ctx.typer ctx.haxe_exception_class method_field (fun t -> t) args return_type p
@@ -52,10 +52,10 @@ let haxe_exception_instance_call ctx haxe_exception method_name args p =
 			match follow cf.cf_type with
 			| TFun(_,t) -> t
 			| _ ->
-				error ((s_type (print_context()) haxe_exception.etype) ^ "." ^ method_name ^ " is not a function and cannot be called") p
+				typing_error ((s_type (print_context()) haxe_exception.etype) ^ "." ^ method_name ^ " is not a function and cannot be called") p
 		in
 		make_call ctx.typer efield args rt p
-	| _ -> error ((s_type (print_context()) haxe_exception.etype) ^ "." ^ method_name ^ " is expected to be an instance method") p
+	| _ -> typing_error ((s_type (print_context()) haxe_exception.etype) ^ "." ^ method_name ^ " is expected to be an instance method") p
 
 (**
 	Generate `Std.isOfType(e, t)`
@@ -65,16 +65,16 @@ let std_is ctx e t p =
 	let std_cls =
 		match Typeload.load_type_raise ctx.typer ([],"Std") "Std" p with
 		| TClassDecl cls -> cls
-		| _ -> error "Std is expected to be a class" p
+		| _ -> typing_error "Std is expected to be a class" p
 	in
 	let isOfType_field =
 		try PMap.find "isOfType" std_cls.cl_statics
-		with Not_found -> error ("Std has no field isOfType") p
+		with Not_found -> typing_error ("Std has no field isOfType") p
 	in
 	let return_type =
 		match follow isOfType_field.cf_type with
 		| TFun(_,t) -> t
-		| _ -> error ("Std.isOfType is not a function and cannot be called") p
+		| _ -> typing_error ("Std.isOfType is not a function and cannot be called") p
 	in
 	let type_expr = { eexpr = TTypeExpr(module_type_of_type t); etype = t; epos = p } in
 	make_static_call ctx.typer std_cls isOfType_field (fun t -> t) [e; type_expr] return_type p
@@ -407,12 +407,12 @@ let filter tctx =
 		and haxe_exception_type, haxe_exception_class =
 			match Typeload.load_instance tctx (tp haxe_exception_type_path) true with
 			| TInst(cls,_) as t -> t,cls
-			| _ -> error "haxe.Exception is expected to be a class" null_pos
+			| _ -> typing_error "haxe.Exception is expected to be a class" null_pos
 		and haxe_native_stack_trace =
 			match Typeload.load_instance tctx (tp (["haxe"],"NativeStackTrace")) true with
 			| TInst(cls,_) -> cls
 			| TAbstract({ a_impl = Some cls },_) -> cls
-			| _ -> error "haxe.NativeStackTrace is expected to be a class or an abstract" null_pos
+			| _ -> typing_error "haxe.NativeStackTrace is expected to be a class or an abstract" null_pos
 		in
 		let ctx = {
 			typer = tctx;
@@ -455,7 +455,7 @@ let insert_save_stacks tctx =
 			match Typeload.load_type_def tctx null_pos tp with
 			| TClassDecl cls -> cls
 			| TAbstractDecl { a_impl = Some cls } -> cls
-			| _ -> error "haxe.NativeStackTrace is expected to be a class or an abstract" null_pos
+			| _ -> typing_error "haxe.NativeStackTrace is expected to be a class or an abstract" null_pos
 		in
 		let rec contains_insertion_points e =
 			match e.eexpr with
@@ -471,12 +471,12 @@ let insert_save_stacks tctx =
 			if has_feature tctx.com "haxe.NativeStackTrace.exceptionStack" then
 				let method_field =
 					try PMap.find "saveStack" native_stack_trace_cls.cl_statics
-					with Not_found -> error ("haxe.NativeStackTrace has no field saveStack") null_pos
+					with Not_found -> typing_error ("haxe.NativeStackTrace has no field saveStack") null_pos
 				in
 				let return_type =
 					match follow method_field.cf_type with
 					| TFun(_,t) -> t
-					| _ -> error ("haxe.NativeStackTrace." ^ method_field.cf_name ^ " is not a function and cannot be called") null_pos
+					| _ -> typing_error ("haxe.NativeStackTrace." ^ method_field.cf_name ^ " is not a function and cannot be called") null_pos
 				in
 				let catch_local = mk (TLocal catch_var) catch_var.v_type catch_var.v_pos in
 				begin
@@ -530,7 +530,7 @@ let patch_constructors tctx =
 					let this = { eexpr = TConst(TThis); etype = t; epos = p } in
 					let faccess =
 						try quick_field t "__shiftStack"
-						with Not_found -> error "haxe.Exception has no field __shiftStack" p
+						with Not_found -> typing_error "haxe.Exception has no field __shiftStack" p
 					in
 					match faccess with
 					| FInstance (_,_,cf) ->
@@ -539,10 +539,10 @@ let patch_constructors tctx =
 							match follow cf.cf_type with
 							| TFun(_,t) -> t
 							| _ ->
-								error "haxe.Exception.__shiftStack is not a function and cannot be called" cf.cf_name_pos
+								typing_error "haxe.Exception.__shiftStack is not a function and cannot be called" cf.cf_name_pos
 						in
 						make_call tctx efield [] rt p
-					| _ -> error "haxe.Exception.__shiftStack is expected to be an instance method" p
+					| _ -> typing_error "haxe.Exception.__shiftStack is expected to be an instance method" p
 				in
 				TypeloadFunction.add_constructor tctx cls true cls.cl_name_pos;
 				Option.may (fun cf -> ignore(follow cf.cf_type)) cls.cl_constructor;

+ 7 - 7
src/filters/filters.ml

@@ -97,8 +97,8 @@ let check_local_vars_init com e =
 					if v.v_name = "this" then com.warning "this might be used before assigning a value to it" e.epos
 					else com.warning ("Local variable " ^ v.v_name ^ " might be used before being initialized") e.epos
 				else
-					if v.v_name = "this" then error "Missing this = value" e.epos
-					else error ("Local variable " ^ v.v_name ^ " used without being initialized") e.epos
+					if v.v_name = "this" then typing_error "Missing this = value" e.epos
+					else typing_error ("Local variable " ^ v.v_name ^ " used without being initialized") e.epos
 			end
 		| TVar (v,eo) ->
 			begin
@@ -278,7 +278,7 @@ let check_abstract_as_value e =
 		match e.eexpr with
 		| TField ({ eexpr = TTypeExpr _ }, _) -> ()
 		| TTypeExpr(TClassDecl {cl_kind = KAbstractImpl a}) when not (Meta.has Meta.RuntimeValue a.a_meta) ->
-			error "Cannot use abstract as value" e.epos
+			typing_error "Cannot use abstract as value" e.epos
 		| _ -> Type.iter loop e
 	in
 	loop e;
@@ -382,7 +382,7 @@ let remove_extern_fields ctx t = match t with
 let check_private_path ctx t = match t with
 	| TClassDecl c when c.cl_private ->
 		let rpath = (fst c.cl_module.m_path,"_" ^ snd c.cl_module.m_path) in
-		if Hashtbl.mem ctx.g.types_module rpath then error ("This private class name will clash with " ^ s_type_path rpath) c.cl_pos;
+		if Hashtbl.mem ctx.g.types_module rpath then typing_error ("This private class name will clash with " ^ s_type_path rpath) c.cl_pos;
 	| _ ->
 		()
 
@@ -567,7 +567,7 @@ let check_cs_events com t = match t with
 		let check fields f =
 			match f.cf_kind with
 			| Var { v_read = AccNormal; v_write = AccNormal } when Meta.has Meta.Event f.cf_meta ->
-				if (has_class_field_flag f CfPublic) then error "@:event fields must be private" f.cf_pos;
+				if (has_class_field_flag f CfPublic) then typing_error "@:event fields must be private" f.cf_pos;
 
 				(* prevent generating reflect helpers for the event in gencommon *)
 				f.cf_meta <- (Meta.SkipReflection, [], f.cf_pos) :: f.cf_meta;
@@ -576,7 +576,7 @@ let check_cs_events com t = match t with
 				let tmeth = (tfun [f.cf_type] com.basic.tvoid) in
 
 				let process_event_method name =
-					let m = try PMap.find name fields with Not_found -> error ("Missing event method: " ^ name) f.cf_pos in
+					let m = try PMap.find name fields with Not_found -> typing_error ("Missing event method: " ^ name) f.cf_pos in
 
 					(* check method signature *)
 					begin
@@ -617,7 +617,7 @@ let check_remove_metadata ctx t = match t with
 let check_void_field ctx t = match t with
 	| TClassDecl c ->
 		let check f =
-			match follow f.cf_type with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed" f.cf_pos | _ -> ();
+			match follow f.cf_type with TAbstract({a_path=[],"Void"},_) -> typing_error "Fields of type Void are not allowed" f.cf_pos | _ -> ();
 		in
 		List.iter check c.cl_ordered_fields;
 		List.iter check c.cl_ordered_statics;

+ 12 - 12
src/generators/genjvm.ml

@@ -213,10 +213,10 @@ let convert_fields gctx pfm =
 module AnnotationHandler = struct
 	let convert_annotations meta =
 		let parse_path e =
-			let sl = try string_list_of_expr_path_raise e with Exit -> Error.error "Field expression expected" (pos e) in
+			let sl = try string_list_of_expr_path_raise e with Exit -> Error.typing_error "Field expression expected" (pos e) in
 			let path = match sl with
 				| s :: sl -> List.rev sl,s
-				| _ -> Error.error "Field expression expected" (pos e)
+				| _ -> Error.typing_error "Field expression expected" (pos e)
 			in
 			path
 		in
@@ -230,13 +230,13 @@ module AnnotationHandler = struct
 			| EField(e1,s) ->
 				let path = parse_path e1 in
 				AEnum(object_path_sig path,s)
-			| _ -> Error.error "Expected value expression" (pos e)
+			| _ -> Error.typing_error "Expected value expression" (pos e)
 		in
 		let parse_value_pair e = match fst e with
 			| EBinop(OpAssign,(EConst(Ident s),_),e1) ->
 				s,parse_value e1
 			| _ ->
-				Error.error "Assignment expression expected" (pos e)
+				Error.typing_error "Assignment expression expected" (pos e)
 		in
 		let parse_expr e = match fst e with
 			| ECall(e1,el) ->
@@ -246,7 +246,7 @@ module AnnotationHandler = struct
 				let values = List.map parse_value_pair el in
 				path,values
 			| _ ->
-				Error.error "Call expression expected" (pos e)
+				Error.typing_error "Call expression expected" (pos e)
 		in
 		ExtList.List.filter_map (fun (m,el,_) -> match m,el with
 			| Meta.Meta,[e] ->
@@ -1461,11 +1461,11 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 					self#expect_reference_type;
 					let path = match jsignature_of_type gctx (type_of_module_type mt) with
 						| TObject(path,_) -> path
-						| _ -> Error.error "Class expected" pe
+						| _ -> Error.typing_error "Class expected" pe
 					in
 					code#instanceof path;
 					Some TBool
-				| _ -> Error.error "Type expression expected" e1.epos
+				| _ -> Error.typing_error "Type expression expected" e1.epos
 			end;
 		| TField(_,FStatic({cl_path = (["java";"lang"],"Math")},{cf_name = ("isNaN" | "isFinite") as name})) ->
 			begin match el with
@@ -1524,7 +1524,7 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 				self#new_native_array jsig el;
 				Some (array_sig jsig)
 			| _ ->
-				Error.error (Printf.sprintf "Bad __array__ type: %s" (s_type (print_context()) tr)) e1.epos;
+				Error.typing_error (Printf.sprintf "Bad __array__ type: %s" (s_type (print_context()) tr)) e1.epos;
 			end
 		| TField(_,FStatic({cl_path = (["haxe"],"Rest$Rest_Impl_")},{cf_name = "createNative"})) ->
 			begin match tr, el with
@@ -1534,7 +1534,7 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 				ignore(NativeArray.create jm#get_code jc#get_pool jsig);
 				Some (array_sig jsig)
 			| _ ->
-				Error.error (Printf.sprintf "Bad __array__ type: %s" (s_type (print_context()) tr)) e1.epos;
+				Error.typing_error (Printf.sprintf "Bad __array__ type: %s" (s_type (print_context()) tr)) e1.epos;
 			end
 		| TField(e1,FStatic(c,({cf_kind = Method (MethNormal | MethInline)} as cf))) ->
 			let tl,tr = self#call_arguments cf.cf_type el in
@@ -1607,7 +1607,7 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 					info.super_call_fields <- tl;
 					hd
 				| _ ->
-					Error.error "Something went wrong" e1.epos
+					Error.typing_error "Something went wrong" e1.epos
 			in
 			let kind = get_construction_mode c cf in
 			begin match kind with
@@ -1925,7 +1925,7 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 			)
 		| TNew(c,tl,el) ->
 			begin match OverloadResolution.maybe_resolve_constructor_overload c tl el with
-			| None -> Error.error "Could not find overload" e.epos
+			| None -> Error.typing_error "Could not find overload" e.epos
 			| Some (c',cf,_) ->
 				let f () =
 					let tl,_ = self#call_arguments cf.cf_type el in
@@ -2096,7 +2096,7 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 				) fl;
 			end
 		| TIdent _ ->
-			Error.error (s_expr_ast false "" (s_type (print_context())) e) e.epos;
+			Error.typing_error (s_expr_ast false "" (s_type (print_context())) e) e.epos;
 
 	(* api *)
 

+ 15 - 15
src/generators/genlua.ml

@@ -76,7 +76,7 @@ let get_exposed ctx path meta = try
         (match args with
          | [ EConst (String(s,_)), _ ] -> [s]
          | [] -> [path]
-         | _ -> error "Invalid @:expose parameters" pos)
+         | _ -> typing_error "Invalid @:expose parameters" pos)
     with Not_found -> []
 
 let dot_path = Globals.s_type_path
@@ -158,7 +158,7 @@ let println ctx =
             newline ctx
         end)
 
-let unsupported p = error "This expression cannot be compiled to Lua" p
+let unsupported p = typing_error "This expression cannot be compiled to Lua" p
 
 let basename path =
     try
@@ -376,7 +376,7 @@ and gen_call ctx e el =
     (match e.eexpr , el with
      | TConst TSuper , params ->
          (match ctx.current.cl_super with
-          | None -> error "Missing api.setCurrentClass" e.epos
+          | None -> typing_error "Missing api.setCurrentClass" e.epos
           | Some (c,_) ->
               print ctx "%s.super(%s" (ctx.type_accessor (TClassDecl c)) (this ctx);
               List.iter (fun p -> print ctx ","; gen_argument ctx p) params;
@@ -384,7 +384,7 @@ and gen_call ctx e el =
          );
      | TField ({ eexpr = TConst TSuper },f) , params ->
          (match ctx.current.cl_super with
-          | None -> error "Missing api.setCurrentClass" e.epos
+          | None -> typing_error "Missing api.setCurrentClass" e.epos
           | Some (c,_) ->
               let name = field_name f in
               print ctx "%s.prototype%s(%s" (ctx.type_accessor (TClassDecl c)) (field name) (this ctx);
@@ -437,7 +437,7 @@ and gen_call ctx e el =
                   if List.length(fields) > 0 then incr count;
               | { eexpr = TConst(TNull)} -> ()
               | _ ->
-                  error "__lua_table__ only accepts array or anonymous object arguments" e.epos;
+				typing_error "__lua_table__ only accepts array or anonymous object arguments" e.epos;
              )) el;
          spr ctx "})";
      | TIdent "__lua__", [{ eexpr = TConst (TString code) }] ->
@@ -626,7 +626,7 @@ and check_multireturn_param ctx t pos =
    match t with
          TAbstract(_,p) | TInst(_,p) ->
             if List.exists ttype_multireturn p then
-                error "MultiReturns must not be type parameters" pos
+				 typing_error "MultiReturns must not be type parameters" pos
             else
                 ()
         | _ ->
@@ -1486,20 +1486,20 @@ let check_multireturn ctx c =
     match c with
     | _ when Meta.has Meta.MultiReturn c.cl_meta ->
         if not (has_class_flag c CExtern) then
-            error "MultiReturns must be externs" c.cl_pos
+            typing_error "MultiReturns must be externs" c.cl_pos
         else if List.length c.cl_ordered_statics > 0 then
-            error "MultiReturns must not contain static fields" c.cl_pos
+            typing_error "MultiReturns must not contain static fields" c.cl_pos
         else if (List.exists (fun cf -> match cf.cf_kind with Method _ -> true | _-> false) c.cl_ordered_fields) then
-            error "MultiReturns must not contain methods" c.cl_pos;
+            typing_error "MultiReturns must not contain methods" c.cl_pos;
     | {cl_super = Some(csup,_)} when Meta.has Meta.MultiReturn csup.cl_meta ->
-        error "Cannot extend a MultiReturn" c.cl_pos
+        typing_error "Cannot extend a MultiReturn" c.cl_pos
     | _ -> ()
 
 
 let check_field_name c f =
     match f.cf_name with
     | "prototype" | "__proto__" | "constructor" ->
-        error ("The field name '" ^ f.cf_name ^ "'  is not allowed in Lua") (match f.cf_expr with None -> c.cl_pos | Some e -> e.epos);
+        typing_error ("The field name '" ^ f.cf_name ^ "'  is not allowed in Lua") (match f.cf_expr with None -> c.cl_pos | Some e -> e.epos);
     | _ -> ()
 
 (* convert a.b.c to ["a"]["b"]["c"] *)
@@ -1587,7 +1587,7 @@ let generate_class ctx c =
     ctx.current <- c;
     ctx.id_counter <- 0;
     (match c.cl_path with
-     | [],"Function" -> error "This class redefines a native one" c.cl_pos
+     | [],"Function" -> typing_error "This class redefines a native one" c.cl_pos
      | _ -> ());
     let p = s_path ctx c.cl_path in
     let hxClasses = has_feature ctx "Type.resolveClass" in
@@ -1785,7 +1785,7 @@ let generate_require ctx path meta =
      | [(EConst(String(module_name,_)),_) ; (EConst(String(object_path,_)),_)] ->
          print ctx "%s = _G.require(\"%s\").%s" p module_name object_path
      | _ ->
-         error "Unsupported @:luaRequire format" mp);
+		typing_error "Unsupported @:luaRequire format" mp);
 
     newline ctx
 
@@ -1800,7 +1800,7 @@ let generate_type ctx = function
         if p = "Std" && c.cl_ordered_statics = [] then
             ()
         else if (not (has_class_flag c CExtern)) && Meta.has Meta.LuaDotMethod c.cl_meta then
-            error "LuaDotMethod is valid for externs only" c.cl_pos
+            typing_error "LuaDotMethod is valid for externs only" c.cl_pos
         else if not (has_class_flag c CExtern) then
             generate_class ctx c;
         check_multireturn ctx c;
@@ -1913,7 +1913,7 @@ let transform_multireturn ctx = function
                         e
                     | TReturn Some(e2) ->
                         if is_multireturn e2.etype then
-                            error "You cannot return a multireturn type from a haxe function" e2.epos
+                            typing_error "You cannot return a multireturn type from a haxe function" e2.epos
                         else
                             Type.map_expr loop e;
      (*

+ 1 - 1
src/generators/genshared.ml

@@ -278,7 +278,7 @@ object(self)
 				in
 				loop csup;
 				(c,cf)
-			| None -> Error.error "Could not find overload constructor" e.epos
+			| None -> Error.typing_error "Could not find overload constructor" e.epos
 		in
 		let find_super_ctor el =
 			let _,cf = find_super_ctor el in

+ 5 - 5
src/macro/eval/evalContext.ml

@@ -502,7 +502,7 @@ let get_static_prototype_raise ctx path =
 
 let get_static_prototype ctx path p =
 	try get_static_prototype_raise ctx path
-	with Not_found -> Error.error (Printf.sprintf "[%i] Type not found: %s" ctx.ctx_id (rev_hash path)) p
+	with Not_found -> Error.typing_error (Printf.sprintf "[%i] Type not found: %s" ctx.ctx_id (rev_hash path)) p
 
 let get_static_prototype_as_value ctx path p =
 	(get_static_prototype ctx path p).pvalue
@@ -512,14 +512,14 @@ let get_instance_prototype_raise ctx path =
 
 let get_instance_prototype ctx path p =
 	try get_instance_prototype_raise ctx path
-	with Not_found -> Error.error (Printf.sprintf "[%i] Instance prototype not found: %s" ctx.ctx_id (rev_hash path)) p
+	with Not_found -> Error.typing_error (Printf.sprintf "[%i] Instance prototype not found: %s" ctx.ctx_id (rev_hash path)) p
 
 let get_instance_constructor_raise ctx path =
 	IntMap.find path ctx.constructors
 
 let get_instance_constructor ctx path p =
 	try get_instance_constructor_raise ctx path
-	with Not_found -> Error.error (Printf.sprintf "[%i] Instance constructor not found: %s" ctx.ctx_id (rev_hash path)) p
+	with Not_found -> Error.typing_error (Printf.sprintf "[%i] Instance constructor not found: %s" ctx.ctx_id (rev_hash path)) p
 
 let get_special_instance_constructor_raise ctx path =
 	Hashtbl.find (get_ctx()).builtins.constructor_builtins path
@@ -529,14 +529,14 @@ let get_proto_field_index_raise proto name =
 
 let get_proto_field_index proto name =
 	try get_proto_field_index_raise proto name
-	with Not_found -> Error.error (Printf.sprintf "Field index for %s not found on prototype %s" (rev_hash name) (rev_hash proto.ppath)) null_pos
+	with Not_found -> Error.typing_error (Printf.sprintf "Field index for %s not found on prototype %s" (rev_hash name) (rev_hash proto.ppath)) null_pos
 
 let get_instance_field_index_raise proto name =
 	IntMap.find name proto.pinstance_names
 
 let get_instance_field_index proto name p =
 	try get_instance_field_index_raise proto name
-	with Not_found -> Error.error (Printf.sprintf "Field index for %s not found on prototype %s" (rev_hash name) (rev_hash proto.ppath)) p
+	with Not_found -> Error.typing_error (Printf.sprintf "Field index for %s not found on prototype %s" (rev_hash name) (rev_hash proto.ppath)) p
 
 let is v path =
 	if path = key_Dynamic then

+ 2 - 2
src/macro/eval/evalExceptions.ml

@@ -145,7 +145,7 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p =
 					in
 					raise (Error.Error (Error.Custom s.sstring,p))
 				| _ ->
-					Error.error "Something went wrong" null_pos
+					Error.typing_error "Something went wrong" null_pos
 		end else begin
 			(* Careful: We have to get the message before resetting the context because toString() might access it. *)
 			let stack = match stack with
@@ -156,7 +156,7 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p =
 			let msg = get_exc_error_message ctx v stack (if p' = null_pos then p else p') in
 			reset_ctx();
 			final();
-			Error.error msg null_pos
+			Error.typing_error msg null_pos
 		end
 	| MacroApi.Abort ->
 		final();

+ 2 - 2
src/macro/eval/evalJit.ml

@@ -235,7 +235,7 @@ and jit_expr jit return e =
 		List.iter (fun var -> ignore(get_capture_slot jit var)) jit_closure.captures_outside_scope;
 		let captures = ExtList.List.filter_map (fun (i,vid,declared) ->
 			if declared then None
-			else Some (i,fst (try Hashtbl.find jit.captures vid with Not_found -> Error.error "Something went wrong" e.epos))
+			else Some (i,fst (try Hashtbl.find jit.captures vid with Not_found -> Error.typing_error "Something went wrong" e.epos))
 		) captures in
 		let mapping = Array.of_list captures in
 		emit_closure ctx mapping eci hasret exec fl
@@ -633,7 +633,7 @@ and jit_expr jit return e =
 	| TParenthesis e1 | TMeta(_,e1) | TCast(e1,None) ->
 		loop e1
 	| TIdent s ->
-		Error.error ("Unknown identifier: " ^ s) e.epos
+		Error.typing_error ("Unknown identifier: " ^ s) e.epos
 	in
 	let f = loop e in
 	begin match ctx.debug.debug_socket with

+ 1 - 1
src/optimization/analyzerTexpr.ml

@@ -1189,7 +1189,7 @@ module Purity = struct
 					apply_to_class com c
 				with Purity_conflict(impure,p) ->
 					com.error "Impure field overrides/implements field which was explicitly marked as @:pure" impure.pn_field.cf_pos;
-					Error.error (Error.compl_msg "Pure field is here") p;
+					Error.typing_error (Error.compl_msg "Pure field is here") p;
 				end
 			| _ -> ()
 		) com.types;

+ 2 - 2
src/optimization/analyzerTexprTransformer.ml

@@ -85,7 +85,7 @@ let rec func ctx bb tf t p =
 		if is_unbound_call_that_might_have_side_effects s el then ctx.has_unbound <- true;
 	in
 	let no_void t p =
-		if ExtType.is_void (follow t) then Error.error "Cannot use Void as value" p
+		if ExtType.is_void (follow t) then Error.typing_error "Cannot use Void as value" p
 	in
 	let push_name s =
 		ctx.name_stack <- s :: ctx.name_stack;
@@ -179,7 +179,7 @@ let rec func ctx bb tf t p =
 			let bb = block_element bb e in
 			bb,mk (TConst TNull) t_dynamic e.epos
 		| TVar _ | TFor _ | TWhile _ ->
-			Error.error "Cannot use this expression as value" e.epos
+			Error.typing_error "Cannot use this expression as value" e.epos
 	and value bb e =
 		let bb,e = value' bb e in
 		no_void e.etype e.epos;

+ 9 - 9
src/optimization/inline.ml

@@ -254,7 +254,7 @@ let inline_config cls_opt cf call_args return_type =
 		let t = if cf.cf_name = "_new" then
 			return_type
 		else if call_args = [] then
-			error "Invalid abstract implementation function" cf.cf_pos
+			typing_error "Invalid abstract implementation function" cf.cf_pos
 		else
 			follow (List.hd call_args).etype
 		in
@@ -386,7 +386,7 @@ class inline_state ctx ethis params cf f p = object(self)
 				(i.i_subst,Some e) :: acc
 			in
 			if i.i_abstract_this && i.i_write then begin
-				if not (is_writable e) then error "Cannot modify the abstract value, store it into a local first" p;
+				if not (is_writable e) then typing_error "Cannot modify the abstract value, store it into a local first" p;
 				accept VIInline
 			end else if i.i_force_temp || (i.i_captured && not (is_constant e)) then
 				reject()
@@ -397,7 +397,7 @@ class inline_state ctx ethis params cf f p = object(self)
 					| TLocal _ | TConst _ ->
 						if not i.i_write then VIInline else VIDoNotInline
 					| TFunction _ ->
-						if i.i_write then error "Cannot modify a closure parameter inside inline method" p;
+						if i.i_write then typing_error "Cannot modify a closure parameter inside inline method" p;
 						if i.i_read <= 1 then VIInline else VIInlineIfCalled
 					| _ ->
 						if not i.i_write && (i.i_read + i.i_called) <= 1 then VIInline else VIDoNotInline
@@ -689,7 +689,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 				l.i_read <- l.i_read + (if !in_loop then 2 else 1);
 				{ e with eexpr = TLocal l.i_subst }
 			| None ->
-				error "Could not inline `this` outside of an instance context" po
+				typing_error "Could not inline `this` outside of an instance context" po
 			)
 		| TVar (v,eo) ->
 			{ e with eexpr = TVar ((state#declare v).i_subst,opt (map false false) eo)}
@@ -697,9 +697,9 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 			if not term then begin
 				match cf.cf_kind with
 				| Method MethInline ->
-					error "Cannot inline a not final return" po
+					typing_error "Cannot inline a not final return" po
 				| _ ->
-					error ("Function " ^ cf.cf_name ^ " cannot be inlined because of a not final return") p
+					typing_error ("Function " ^ cf.cf_name ^ " cannot be inlined because of a not final return") p
 			end;
 			(match eo with
 			| None -> mk (TConst TNull) f.tf_type p
@@ -816,9 +816,9 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 			| TInst({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some ({eexpr = TFunction tf})} as cf)} as c,_) ->
 				begin match type_inline_ctor ctx c cf tf ethis el po with
 				| Some e -> map term false e
-				| None -> error "Could not inline super constructor call" po
+				| None -> typing_error "Could not inline super constructor call" po
 				end
-			| _ -> error "Cannot inline function containing super" po
+			| _ -> typing_error "Cannot inline function containing super" po
 			end
 		| TCall(e1,el) ->
 			state#set_side_effect;
@@ -826,7 +826,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 			let el = List.map (map false false) el in
 			{e with eexpr = TCall(e1,el)}
 		| TConst TSuper ->
-			error "Cannot inline function containing super" po
+			typing_error "Cannot inline function containing super" po
 		| TMeta((Meta.Ast,_,_) as m,e1) when term ->
 			(* Special case for @:ast-wrapped TSwitch nodes: If the recursion alters the type of the TSwitch node, we also want
 			   to alter the type of the TMeta node. *)

+ 1 - 1
src/optimization/inlineConstructors.ml

@@ -403,7 +403,7 @@ let inline_constructors ctx original_e =
 						None
 				end
 			| TNew({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some _} as cf)} as c,_,pl),_ when is_extern_ctor c cf ->
-				error "Extern constructor could not be inlined" e.epos;
+				typing_error "Extern constructor could not be inlined" e.epos;
 			| TObjectDecl fl, _ when captured && fl <> [] && List.for_all (fun((s,_,_),_) -> Lexer.is_valid_identifier s) fl ->
 				let v = alloc_var VGenerated "inlobj" e.etype e.epos in
 				let ev = mk (TLocal v) v.v_type e.epos in

+ 1 - 1
src/optimization/optimizer.ml

@@ -198,7 +198,7 @@ let reduce_expr com e =
 		List.iter (fun (cl,_) ->
 			List.iter (fun e ->
 				match e.eexpr with
-				| TCall ({ eexpr = TField (_,FEnum _) },_) -> error "Not-constant enum in switch cannot be matched" e.epos
+				| TCall ({ eexpr = TField (_,FEnum _) },_) -> typing_error "Not-constant enum in switch cannot be matched" e.epos
 				| _ -> ()
 			) cl
 		) cases;

+ 1 - 1
src/optimization/optimizerTexpr.ml

@@ -215,7 +215,7 @@ let optimize_binop e op e1 e2 =
 		| OpAssign,_ ->
 			e
 		| _ ->
-			error "You cannot directly compare enums with arguments. Use either `switch`, `match` or `Type.enumEq`" e.epos
+			typing_error "You cannot directly compare enums with arguments. Use either `switch`, `match` or `Type.enumEq`" e.epos
 		end
 	| _ ->
 		e)

+ 7 - 7
src/typing/callUnification.ml

@@ -302,12 +302,12 @@ let unify_field_call ctx fa el_typed el p inline =
 			in
 			make_field_call_candidate el ret monos tf cf (mk_call,extract_delayed_display())
 		| t ->
-			error (s_type (print_context()) t ^ " cannot be called") p
+			typing_error (s_type (print_context()) t ^ " cannot be called") p
 	in
 	let maybe_raise_unknown_ident cerr p =
 		let rec loop err =
 			match err with
-			| Unknown_ident _ -> error (error_msg err) p
+			| Unknown_ident _ -> typing_error (error_msg err) p
 			| Stack (e1,e2) -> (loop e1; loop e2)
 			| _ -> ()
 		in
@@ -380,14 +380,14 @@ let unify_field_call ctx fa el_typed el p inline =
 			let failures = remove_duplicates (fun (_,msg1,_) (_,msg2,_) -> msg1 <> msg2) failures in
 			begin match failures with
 			| [_,msg,p] ->
-				error msg p
+				typing_error msg p
 			| _ ->
 				display_error ctx "Could not find a suitable overload, reasons follow" p;
 				List.iter (fun (cf,msg,p2) ->
 					display_error ctx ("Overload resolution failed for " ^ (s_type (print_context()) cf.cf_type)) p;
 					display_error ctx msg p2;
 				) failures;
-				error "End of overload failure reasons" p
+				typing_error "End of overload failure reasons" p
 			end
 		in
 		if overload_kind = OverloadProper then begin match Overloads.Resolution.reduce_compatible candidates with
@@ -431,7 +431,7 @@ object(self)
 		end
 
 	method private macro_call (ethis : texpr) (cf : tclass_field) (el : expr list) =
-		if ctx.macro_depth > 300 then error "Stack overflow" p;
+		if ctx.macro_depth > 300 then typing_error "Stack overflow" p;
 		ctx.macro_depth <- ctx.macro_depth + 1;
 		ctx.with_type_stack <- with_type :: ctx.with_type_stack;
 		let ethis_f = ref (fun () -> ()) in
@@ -499,7 +499,7 @@ object(self)
 			else if ctx.untyped then
 				mk_mono()
 			else
-				error (s_type (print_context()) e.etype ^ " cannot be called") e.epos
+				typing_error (s_type (print_context()) e.etype ^ " cannot be called") e.epos
 			in
 			mk (TCall (e,el)) t p
 		in
@@ -560,7 +560,7 @@ object(self)
 				let name = Printf.sprintf "%s_%s" (if is_set then "set" else "get") fa.fa_field.cf_name in
 				make_call ctx (mk (TField (e,quick_field_dynamic e.etype name)) tf p) el_typed t p
 			| _ ->
-				error "Could not resolve accessor" p
+				typing_error "Could not resolve accessor" p
 
 	(* Calls the field represented by `fa` with the typed arguments `el_typed` and the syntactic arguments `el`.
 

+ 9 - 9
src/typing/calls.ml

@@ -47,7 +47,7 @@ let make_call ctx e params t ?(force_inline=false) p =
 						PMap.mem f.cf_name c.cl_fields
 						|| List.exists has_override c.cl_descendants
 					in
-					if List.exists has_override c.cl_descendants then error (Printf.sprintf "Cannot force inline-call to %s because it is overridden" f.cf_name) p
+					if List.exists has_override c.cl_descendants then typing_error (Printf.sprintf "Cannot force inline-call to %s because it is overridden" f.cf_name) p
 				)
 		end;
 		let config = Inline.inline_config cl f params t in
@@ -63,7 +63,7 @@ let make_call ctx e params t ?(force_inline=false) p =
 						(* Current method needs to infer CfModifiesThis flag, since we are calling a method, which modifies `this` *)
 						add_class_field_flag ctx.curfield CfModifiesThis
 					else
-						error ("Abstract 'this' value can only be modified inside an inline function. '" ^ f.cf_name ^ "' modifies 'this'") p;
+						typing_error ("Abstract 'this' value can only be modified inside an inline function. '" ^ f.cf_name ^ "' modifies 'this'") p;
 			| _ -> ()
 		);
 		let params = List.map (ctx.g.do_optimize ctx) params in
@@ -73,7 +73,7 @@ let make_call ctx e params t ?(force_inline=false) p =
 		| None,Some { eexpr = TFunction fd } ->
 			(match Inline.type_inline ctx f fd ethis params t config p force_inline with
 			| None ->
-				if force_inline then error "Inline could not be done" p;
+				if force_inline then typing_error "Inline could not be done" p;
 				raise Exit;
 			| Some e -> e)
 		| _ ->
@@ -188,12 +188,12 @@ let rec acc_get ctx g p =
 		| Var _,None when ctx.com.display.dms_display ->
 			 FieldAccess.get_field_expr fa FRead
 		| Var _,None ->
-			error "Recursive inline is not supported" p
+			typing_error "Recursive inline is not supported" p
 		end
 	in
 	let dispatcher () = new call_dispatcher ctx MGet WithType.value p in
 	match g with
-	| AKNo f -> error ("Field " ^ f ^ " cannot be accessed for reading") p
+	| AKNo f -> typing_error ("Field " ^ f ^ " cannot be accessed for reading") p
 	| AKExpr e -> e
 	| AKAccess _ -> die "" __LOC__
 	| AKResolve(sea,name) ->
@@ -215,7 +215,7 @@ let rec acc_get ctx g p =
 			if ctx.in_display then
 				FieldAccess.get_field_expr fa FRead
 			else
-				error "Invalid macro access" p
+				typing_error "Invalid macro access" p
 		| _ ->
 			if fa.fa_inline then
 				inline_read fa
@@ -268,7 +268,7 @@ let build_call ?(mode=MGet) ctx acc el (with_type:WithType.t) p =
 		dispatch#expr_call (dispatch#resolve_call sea name) [] el
 	| AKNo _ | AKAccess _ ->
 		ignore(acc_get ctx acc p);
-		error ("Unexpected access mode, please report this: " ^ (s_access_kind acc)) p
+		typing_error ("Unexpected access mode, please report this: " ^ (s_access_kind acc)) p
 	| AKAccessor fa ->
 		let e = dispatch#field_call fa [] [] in
 		dispatch#expr_call e [] el
@@ -326,7 +326,7 @@ let type_bind ctx (e : texpr) (args,ret) params p =
 	in
 	let rec loop args params given_args missing_args ordered_args = match args, params with
 		| [], [] -> given_args,missing_args,ordered_args
-		| [], _ -> error "Too many callback arguments" p
+		| [], _ -> typing_error "Too many callback arguments" p
 		| (n,o,t) :: args , [] when o ->
 			let a = if is_pos_infos t then
 					let infos = mk_infos ctx p [] in
@@ -338,7 +338,7 @@ let type_bind ctx (e : texpr) (args,ret) params p =
 			in
 			loop args [] given_args missing_args a
 		| (n,o,t) :: _ , (EConst(Ident "_"),p) :: _ when not ctx.com.config.pf_can_skip_non_nullable_argument && o && not (is_nullable t) ->
-			error "Usage of _ is not supported for optional non-nullable arguments" p
+			typing_error "Usage of _ is not supported for optional non-nullable arguments" p
 		| (n,o,t) :: args , ([] as params)
 		| (n,o,t) :: args , (EConst(Ident "_"),_) :: params ->
 			let v = alloc_var VGenerated (alloc_name n) (if o then ctx.t.tnull t else t) p in

+ 1 - 1
src/typing/fieldAccess.ml

@@ -139,7 +139,7 @@ let get_constructor_access c tl p =
 		in
 		create e_static cf fh false p
 	with Not_found ->
-		raise_error (No_constructor (match c.cl_kind with
+		raise_typing_error (No_constructor (match c.cl_kind with
 			| KAbstractImpl a -> TAbstractDecl a
 			| _ -> TClassDecl c
 		)) p

+ 7 - 7
src/typing/fields.ml

@@ -73,7 +73,7 @@ let field_type ctx c pl f p =
 		apply_params l monos f.cf_type
 
 let no_abstract_constructor c p =
-	if has_class_flag c CAbstract then raise_error (Abstract_class (TClassDecl c)) p
+	if has_class_flag c CAbstract then raise_typing_error (Abstract_class (TClassDecl c)) p
 
 let check_constructor_access ctx c f p =
 	if (Meta.has Meta.CompilerGenerated f.cf_meta) then display_error ctx (error_msg (No_constructor (TClassDecl c))) p;
@@ -89,7 +89,7 @@ let check_no_closure_meta ctx cf fa mode p =
 					Meta.has Meta.NoClosure cl_meta
 					|| Meta.has Meta.NoClosure f.cf_meta
 				then
-					error ("Method " ^ f.cf_name ^ " cannot be used as a value") p
+					typing_error ("Method " ^ f.cf_name ^ " cannot be used as a value") p
 			| _ -> ()
 		in
 		begin match cf.cf_kind with
@@ -115,7 +115,7 @@ let field_access ctx mode f fh e pfield =
 	match f.cf_kind with
 	| Method m ->
 		let normal () = AKField(make_access false) in
-		if is_set && m <> MethDynamic && not ctx.untyped then error "Cannot rebind this method : please use 'dynamic' before method declaration" pfield;
+		if is_set && m <> MethDynamic && not ctx.untyped then typing_error "Cannot rebind this method : please use 'dynamic' before method declaration" pfield;
 		let maybe_check_visibility c static =
 			(* For overloads we have to resolve the actual field before we can check accessibility. *)
 			begin match mode with
@@ -250,7 +250,7 @@ let field_access ctx mode f fh e pfield =
 		| AccRequire (r,msg) ->
 			match msg with
 			| None -> error_require r pfield
-			| Some msg -> error msg pfield
+			| Some msg -> typing_error msg pfield
 
 let class_field ctx c tl name p =
 	raw_class_field (fun f -> field_type ctx c tl f p) c tl name
@@ -285,7 +285,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 		let _,el,_ = Meta.get meta a.a_meta in
 		if el <> [] && not (List.exists (fun e -> match fst e with
 			| EConst (Ident i' | String (i',_)) -> i' = i
-			| _ -> error "Identifier or string expected as argument to @:forward" (pos e)
+			| _ -> typing_error "Identifier or string expected as argument to @:forward" (pos e)
 		) el) then raise Not_found;
 		f()
 	in
@@ -515,7 +515,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 				in
 				loop c tl
 			with Not_found when PMap.mem i c.cl_statics ->
-				error ("Cannot access static field " ^ i ^ " from a class instance") pfield;
+				typing_error ("Cannot access static field " ^ i ^ " from a class instance") pfield;
 			)
 		| TDynamic t ->
 			AKExpr (mk (TField (e,FDynamic i)) t p)
@@ -529,7 +529,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 			with Not_found -> try
 				type_field_by_forward_member type_field_by_fallback e a tl
 			with Not_found when not (has_class_field_flag (PMap.find i (find_some a.a_impl).cl_statics) CfImpl) ->
-				error ("Invalid call to static function " ^ i ^ " through abstract instance") pfield
+				typing_error ("Invalid call to static function " ^ i ^ " through abstract instance") pfield
 			)
 		| _ -> raise Not_found
 	in

+ 4 - 4
src/typing/finalization.ml

@@ -29,20 +29,20 @@ let get_main ctx types =
 				let t = Typeload.find_type_in_module_raise ctx m name null_pos in
 				match t with
 				| TEnumDecl _ | TTypeDecl _ | TAbstractDecl _ ->
-					error ("Invalid -main : " ^ s_type_path path ^ " is not a class") null_pos
+					typing_error ("Invalid -main : " ^ s_type_path path ^ " is not a class") null_pos
 				| TClassDecl c ->
 					p := c.cl_pos;
 					c, PMap.find "main" c.cl_statics
 			with Not_found ->
-				error ("Invalid -main : " ^ s_type_path path ^ " does not have static function main") !p
+				typing_error ("Invalid -main : " ^ s_type_path path ^ " does not have static function main") !p
 		in
 		let ft = Type.field_type f in
 		let fmode, r =
 			match follow ft with
 			| TFun ([],r) -> FStatic (c,f), r
-			| _ -> error ("Invalid -main : " ^ s_type_path path ^ " has invalid main function") c.cl_pos
+			| _ -> typing_error ("Invalid -main : " ^ s_type_path path ^ " has invalid main function") c.cl_pos
 		in
-		if not (ExtType.is_void (follow r)) then error (Printf.sprintf "Return type of main function should be Void (found %s)" (s_type (print_context()) r)) f.cf_name_pos;
+		if not (ExtType.is_void (follow r)) then typing_error (Printf.sprintf "Return type of main function should be Void (found %s)" (s_type (print_context()) r)) f.cf_name_pos;
 		f.cf_meta <- (Dce.mk_keep_meta f.cf_pos) :: f.cf_meta;
 		let emain = type_module_type ctx (TClassDecl c) None null_pos in
 		let main = mk (TCall (mk (TField (emain,fmode)) ft null_pos,[])) r null_pos in

+ 5 - 5
src/typing/forLoop.ml

@@ -280,7 +280,7 @@ module IterationKind = struct
 				| TBinop (OpAssignOp _,{ eexpr = TLocal l },_)
 				| TUnop (Increment,_,{ eexpr = TLocal l })
 				| TUnop (Decrement,_,{ eexpr = TLocal l })  when List.memq l vl ->
-					error "Loop variable cannot be modified" e.epos
+					typing_error "Loop variable cannot be modified" e.epos
 				| _ ->
 					Type.iter loop e
 			in
@@ -317,7 +317,7 @@ module IterationKind = struct
 		match iterator.it_kind with
 		| IteratorIntUnroll(offset,length,ascending) ->
 			check_loop_var_modification [v] e2;
-			if not ascending then error "Cannot iterate backwards" p;
+			if not ascending then typing_error "Cannot iterate backwards" p;
 			let el = ExtList.List.init length (fun i ->
 				let ei = make_int ctx.t (if ascending then i + offset else offset - i) p in
 				let rec loop e = match e.eexpr with
@@ -330,7 +330,7 @@ module IterationKind = struct
 			mk (TBlock el) t_void p
 		| IteratorIntConst(a,b,ascending) ->
 			check_loop_var_modification [v] e2;
-			if not ascending then error "Cannot iterate backwards" p;
+			if not ascending then typing_error "Cannot iterate backwards" p;
 			let v_index = gen_local ctx t_int a.epos in
 			let evar_index = mk (TVar(v_index,Some a)) t_void a.epos in
 			let ev_index = make_local v_index v_index.v_pos in
@@ -460,7 +460,7 @@ let type_for_loop ctx handle_display it e2 p =
 	let rec loop_ident dko e1 = match e1 with
 		| EConst(Ident i),p -> i,p,dko
 		| EDisplay(e1,dk),_ -> loop_ident (Some dk) e1
-		| _ -> error "Identifier expected" (pos e1)
+		| _ -> typing_error "Identifier expected" (pos e1)
 	in
 	let rec loop dko e1 = match fst e1 with
 		| EBinop(OpIn,e1,e2) ->
@@ -475,7 +475,7 @@ let type_for_loop ctx handle_display it e2 p =
 			| Some dk -> ignore(handle_display ctx e1 dk MGet WithType.value);
 			| None -> ()
 			end;
-			error "For expression should be 'v in expr'" (snd it)
+			typing_error "For expression should be 'v in expr'" (snd it)
 	in
 	let ik,e1 = loop None it in
 	let e1 = type_expr ctx e1 WithType.value in

+ 3 - 3
src/typing/functionArguments.ml

@@ -91,9 +91,9 @@ object(self)
 
 	method private check_rest (is_last : bool) (eo : expr option) (opt : bool) (t : Type.t) (pn : pos) =
 		if ExtType.is_rest (follow t) then begin
-			if opt then error "Rest argument cannot be optional" pn;
-			begin match eo with None -> () | Some (_,p) -> error "Rest argument cannot have default value" p end;
-			if not is_last then error "Rest should only be used for the last function argument" pn;
+			if opt then typing_error "Rest argument cannot be optional" pn;
+			begin match eo with None -> () | Some (_,p) -> typing_error "Rest argument cannot have default value" p end;
+			if not is_last then typing_error "Rest should only be used for the last function argument" pn;
 		end
 
 	(* Returns the `(tvar * texpr option) list` for `tf_args`. Also checks the validity of argument names and whether or not

+ 11 - 11
src/typing/generic.ml

@@ -111,7 +111,7 @@ let generic_substitute_expr gctx e =
 				let fa = try
 					quick_field t cf.cf_name
 				with Not_found ->
-					error (Printf.sprintf "Type %s has no field %s (possible typing order issue)" (s_type (print_context()) t) cf.cf_name) e.epos
+					typing_error (Printf.sprintf "Type %s has no field %s (possible typing order issue)" (s_type (print_context()) t) cf.cf_name) e.epos
 				in
 				build_expr {e with eexpr = TField(e1,fa)}
 			end;
@@ -128,7 +128,7 @@ let generic_substitute_expr gctx e =
 				let eo = loop gctx.subst in
 				begin match eo with
 					| Some e -> e
-					| None -> error "Only Const type parameters can be used as value" e.epos
+					| None -> typing_error "Only Const type parameters can be used as value" e.epos
 				end
 			with Not_found ->
 				e
@@ -155,7 +155,7 @@ let static_method_container gctx c cf p =
 		let t = Typeload.load_instance ctx (mk_type_path (pack,name),p) true in
 		match t with
 		| TInst(cg,_) -> cg
-		| _ -> error ("Cannot specialize @:generic static method because the generated type name is already used: " ^ name) p
+		| _ -> typing_error ("Cannot specialize @:generic static method because the generated type name is already used: " ^ name) p
 	with Error(Module_not_found path,_) when path = (pack,name) ->
 		let m = (try Hashtbl.find ctx.g.modules (Hashtbl.find ctx.g.types_module c.cl_path) with Not_found -> die "" __LOC__) in
 		let mg = {
@@ -182,7 +182,7 @@ let rec build_generic ctx c p tl =
 			(match c2.cl_kind with
 			| KTypeParameter tl ->
 				if not (TypeloadCheck.is_generic_parameter ctx c2) && has_ctor_constraint c2 then
-					error "Type parameters with a constructor cannot be used non-generically" p;
+					typing_error "Type parameters with a constructor cannot be used non-generically" p;
 				recurse := true
 			| _ -> ());
 			List.iter check_recursive tl;
@@ -199,7 +199,7 @@ let rec build_generic ctx c p tl =
 		let t = Typeload.load_instance ctx (mk_type_path (pack,name),p) false in
 		match t with
 		| TInst({ cl_kind = KGenericInstance (csup,_) },_) when c == csup -> t
-		| _ -> error ("Cannot specialize @:generic because the generated type name is already used: " ^ name) p
+		| _ -> typing_error ("Cannot specialize @:generic because the generated type name is already used: " ^ name) p
 	with Error(Module_not_found path,_) when path = (pack,name) ->
 		let m = (try Hashtbl.find ctx.g.modules (Hashtbl.find ctx.g.types_module c.cl_path) with Not_found -> die "" __LOC__) in
 		(* let ctx = { ctx with m = { ctx.m with module_types = m.m_types @ ctx.m.module_types } } in *)
@@ -280,7 +280,7 @@ let rec build_generic ctx c p tl =
 					| Some e ->
 						cf_new.cf_expr <- Some (generic_substitute_expr gctx e)
 				) with Unify_error l ->
-					error (error_msg (Unify l)) cf_new.cf_pos
+					typing_error (error_msg (Unify l)) cf_new.cf_pos
 				end;
 				t
 			in
@@ -295,10 +295,10 @@ let rec build_generic ctx c p tl =
 			cf_new.cf_type <- TLazy r;
 			cf_new
 		in
-		if c.cl_init <> None then error "This class can't be generic" p;
+		if c.cl_init <> None then typing_error "This class can't be generic" p;
 		List.iter (fun cf -> match cf.cf_kind with
 			| Method MethMacro when not ctx.in_macro -> ()
-			| _ -> error "A generic class can't have static fields" cf.cf_pos
+			| _ -> typing_error "A generic class can't have static fields" cf.cf_pos
 		) c.cl_ordered_statics;
 		cg.cl_super <- (match c.cl_super with
 			| None -> None
@@ -321,7 +321,7 @@ let rec build_generic ctx c p tl =
 			| _, Some cf, _ -> Some (build_field cf)
 			| Some ctor, _, _ -> Some ctor
 			| None, None, None -> None
-			| _ -> error "Please define a constructor for this class in order to use it as generic" c.cl_pos
+			| _ -> typing_error "Please define a constructor for this class in order to use it as generic" c.cl_pos
 		);
 		cg.cl_implements <- List.map (fun (i,tl) ->
 			(match follow (generic_substitute_type gctx (TInst (i, List.map (generic_substitute_type gctx) tl))) with
@@ -349,7 +349,7 @@ let type_generic_function ctx fa fcc with_type p =
 		| _ -> die "" __LOC__
 	in
 	let cf = fcc.fc_field in
-	if cf.cf_params = [] then error "Function has no type parameters and cannot be generic" p;
+	if cf.cf_params = [] then typing_error "Function has no type parameters and cannot be generic" p;
 	begin match with_type with
 		| WithType.WithType(t,_) -> unify ctx fcc.fc_ret t p
 		| _ -> ()
@@ -448,7 +448,7 @@ let type_generic_function ctx fa fcc with_type p =
 		let dispatch = new CallUnification.call_dispatcher ctx (MCall []) with_type p in
 		dispatch#field_call fa el []
 	with Generic_Exception (msg,p) ->
-		error msg p)
+		typing_error msg p)
 
 ;;
 Typecore.type_generic_function_ref := type_generic_function

+ 6 - 6
src/typing/instanceBuilder.ml

@@ -9,7 +9,7 @@ let get_macro_path ctx e args p =
 		match fst e with
 		| EField (e,f) -> f :: loop e
 		| EConst (Ident i) -> [i]
-		| _ -> error "Invalid macro call" p
+		| _ -> typing_error "Invalid macro call" p
 	in
 	let path = match e with
 		| (EConst(Ident i)),_ ->
@@ -19,7 +19,7 @@ let get_macro_path ctx e args p =
 			with Not_found -> try
 				(t_infos (let path,_,_ = PMap.find i ctx.m.module_globals in path)).mt_path
 			with Not_found ->
-				error "Invalid macro call" p
+				typing_error "Invalid macro call" p
 			in
 			i :: (snd path) :: (fst path)
 		| _ ->
@@ -27,7 +27,7 @@ let get_macro_path ctx e args p =
 	in
 	(match path with
 	| meth :: cl :: path -> (List.rev path,cl), meth, args
-	| _ -> error "Invalid macro call" p)
+	| _ -> typing_error "Invalid macro call" p)
 
 let build_macro_type ctx pl p =
 	let path, field, args = (match pl with
@@ -35,7 +35,7 @@ let build_macro_type ctx pl p =
 		| [TInst ({ cl_kind = KExpr (EArrayDecl [ECall (e,args),_],_) },_)] ->
 			get_macro_path ctx e args p
 		| _ ->
-			error "MacroType requires a single expression call parameter" p
+			typing_error "MacroType requires a single expression call parameter" p
 	) in
 	let old = ctx.ret in
 	let t = (match ctx.g.do_macro ctx MMacroType path field args p with
@@ -49,11 +49,11 @@ let build_macro_build ctx c pl cfl p =
 	let path, field, args =
 		let build_expr =
 			try Meta.get Meta.GenericBuild c.cl_meta
-			with Not_found -> error ((s_type_path c.cl_path) ^ " is missing @:genericBuild meta. Was it removed by a macro?") p
+			with Not_found -> typing_error ((s_type_path c.cl_path) ^ " is missing @:genericBuild meta. Was it removed by a macro?") p
 		in
 		match build_expr with
 		| _,[ECall(e,args),_],_ -> get_macro_path ctx e args p
-		| _ -> error "genericBuild requires a single expression call parameter" p
+		| _ -> typing_error "genericBuild requires a single expression call parameter" p
 	in
 	let old = ctx.ret,ctx.get_build_infos in
 	ctx.get_build_infos <- (fun() -> Some (TClassDecl c, pl, cfl));

+ 16 - 16
src/typing/macroContext.ml

@@ -53,7 +53,7 @@ let safe_decode ctx v expected t p f =
 		let errors = Interp.handle_decoding_error (output_string ch) v t in
 		List.iter (fun (s,i) -> Printf.fprintf ch "\nline %i: %s" i s) (List.rev errors);
 		close_out ch;
-		error (Printf.sprintf "Expected %s but got %s (see %s.txt for details)" expected (Interp.value_string v) (String.concat "/" path)) p
+		typing_error (Printf.sprintf "Expected %s but got %s (see %s.txt for details)" expected (Interp.value_string v) (String.concat "/" path)) p
 
 let get_next_stored_typed_expr_id =
 	let uid = ref 0 in
@@ -126,18 +126,18 @@ let load_macro_ref : (typer -> bool -> path -> string -> pos -> (typer * ((strin
 let make_macro_api ctx p =
 	let parse_expr_string s p inl =
 		typing_timer ctx false (fun() ->
-			match ParserEntry.parse_expr_string ctx.com.defines s p error inl with
+			match ParserEntry.parse_expr_string ctx.com.defines s p typing_error inl with
 				| ParseSuccess(data,true,_) when inl -> data (* ignore errors when inline-parsing in display file *)
 				| ParseSuccess(data,_,_) -> data
 				| ParseError _ -> raise MacroApi.Invalid_expr)
 	in
 	let parse_metadata s p =
 		try
-			match ParserEntry.parse_string Grammar.parse_meta ctx.com.defines s null_pos error false with
+			match ParserEntry.parse_string Grammar.parse_meta ctx.com.defines s null_pos typing_error false with
 			| ParseSuccess(meta,_,_) -> meta
-			| ParseError(_,_,_) -> error "Malformed metadata string" p
+			| ParseError(_,_,_) -> typing_error "Malformed metadata string" p
 		with _ ->
-			error "Malformed metadata string" p
+			typing_error "Malformed metadata string" p
 	in
 	{
 		MacroApi.pos = p;
@@ -217,7 +217,7 @@ let make_macro_api ctx p =
 		MacroApi.type_patch = (fun t f s v ->
 			typing_timer ctx false (fun() ->
 				let v = (match v with None -> None | Some s ->
-					match ParserEntry.parse_string Grammar.parse_complex_type ctx.com.defines s null_pos error false with
+					match ParserEntry.parse_string Grammar.parse_complex_type ctx.com.defines s null_pos typing_error false with
 					| ParseSuccess((ct,_),_,_) -> Some ct
 					| ParseError(_,(msg,p),_) -> Parser.error msg p (* p is null_pos, but we don't have anything else here... *)
 				) in
@@ -544,15 +544,15 @@ let load_macro' ctx display cpath f p =
 			with Not_found ->
 				let name = Option.default (snd mpath) sub in
 				let path = fst mpath, name in
-				let mt = try List.find (fun t2 -> (t_infos t2).mt_path = path) mloaded.m_types with Not_found -> raise_error (Type_not_found (mloaded.m_path,name,Not_defined)) p in
+				let mt = try List.find (fun t2 -> (t_infos t2).mt_path = path) mloaded.m_types with Not_found -> raise_typing_error (Type_not_found (mloaded.m_path,name,Not_defined)) p in
 				match mt with
 				| TClassDecl c ->
 					mctx.g.do_finalize mctx;
-					c, (try PMap.find f c.cl_statics with Not_found -> error ("Method " ^ f ^ " not found on class " ^ s_type_path cpath) p)
-				| _ -> error "Macro should be called on a class" p
+					c, (try PMap.find f c.cl_statics with Not_found -> typing_error ("Method " ^ f ^ " not found on class " ^ s_type_path cpath) p)
+				| _ -> typing_error "Macro should be called on a class" p
 		in
 		api.MacroApi.current_macro_module <- (fun() -> mloaded);
-		let meth = (match follow meth.cf_type with TFun (args,ret) -> (args,ret,cl,meth),mloaded | _ -> error "Macro call should be a method" p) in
+		let meth = (match follow meth.cf_type with TFun (args,ret) -> (args,ret,cl,meth),mloaded | _ -> typing_error "Macro call should be a method" p) in
 		restore();
 		if not ctx.in_macro then flush_macro_context mint ctx;
 		Hashtbl.add mctx.com.cached_macros (cpath,f) meth;
@@ -772,13 +772,13 @@ let call_macro ctx path meth args p =
 	let mctx, (margs,_,mclass,mfield), call = load_macro ctx false path meth p in
 	mctx.curclass <- null_class;
 	let el, _ = CallUnification.unify_call_args mctx args margs t_dynamic p false false false in
-	call (List.map (fun e -> try Interp.make_const e with Exit -> error "Parameter should be a constant" e.epos) el)
+	call (List.map (fun e -> try Interp.make_const e with Exit -> typing_error "Parameter should be a constant" e.epos) el)
 
 let call_init_macro ctx e =
 	let p = { pfile = "--macro " ^ e; pmin = -1; pmax = -1 } in
 	let e = try
-		if String.get e (String.length e - 1) = ';' then error "Unexpected ;" p;
-		begin match ParserEntry.parse_expr_string ctx.com.defines e p error false with
+		if String.get e (String.length e - 1) = ';' then typing_error "Unexpected ;" p;
+		begin match ParserEntry.parse_expr_string ctx.com.defines e p typing_error false with
 		| ParseSuccess(data,_,_) -> data
 		| ParseError(_,(msg,p),_) -> (Parser.error msg p)
 		end
@@ -792,16 +792,16 @@ let call_init_macro ctx e =
 			match fst e with
 			| EField (e,f) -> f :: loop e
 			| EConst (Ident i) -> [i]
-			| _ -> error "Invalid macro call" p
+			| _ -> typing_error "Invalid macro call" p
 		in
 		let path, meth = (match loop e with
 		| [meth] -> (["haxe";"macro"],"Compiler"), meth
 		| [meth;"server"] -> (["haxe";"macro"],"CompilationServer"), meth
 		| meth :: cl :: path -> (List.rev path,cl), meth
-		| _ -> error "Invalid macro call" p) in
+		| _ -> typing_error "Invalid macro call" p) in
 		ignore(call_macro ctx path meth args p);
 	| _ ->
-		error "Invalid macro call" p
+		typing_error "Invalid macro call" p
 
 let interpret ctx =
 	let mctx = Interp.create ctx.com (make_macro_api ctx null_pos) false in

+ 5 - 5
src/typing/magicTypes.ml

@@ -11,7 +11,7 @@ open Error
 (* REMOTING PROXYS *)
 
 let extend_remoting ctx c t p async prot =
-	if c.cl_super <> None then error "Cannot extend several classes" p;
+	if c.cl_super <> None then typing_error "Cannot extend several classes" p;
 	(* remove forbidden packages *)
 	let rules = ctx.com.package_rules in
 	ctx.com.package_rules <- PMap.foldi (fun key r acc -> match r with Forbidden -> acc | _ -> PMap.add key r acc) rules PMap.empty;
@@ -28,7 +28,7 @@ let extend_remoting ctx c t p async prot =
 	let file, decls = (try
 		TypeloadParse.parse_module ctx path p
 	with
-		| Not_found -> ctx.com.package_rules <- rules; error ("Could not load proxy module " ^ s_type_path path ^ (if fst path = [] then " (try using absolute path)" else "")) p
+		| Not_found -> ctx.com.package_rules <- rules; typing_error ("Could not load proxy module " ^ s_type_path path ^ (if fst path = [] then " (try using absolute path)" else "")) p
 		| e -> ctx.com.package_rules <- rules; raise e) in
 	ctx.com.package_rules <- rules;
 	let base_fields = [
@@ -41,7 +41,7 @@ let extend_remoting ctx c t p async prot =
 			acc
 		else match f.cff_kind with
 		| FFun fd when (is_public || List.mem_assoc APublic f.cff_access) && not (List.mem_assoc AStatic f.cff_access) ->
-			if List.exists (fun (_,_,_,t,_) -> t = None) fd.f_args then error ("Field " ^ fst f.cff_name ^ " type is not complete and cannot be used by RemotingProxy") p;
+			if List.exists (fun (_,_,_,t,_) -> t = None) fd.f_args then typing_error ("Field " ^ fst f.cff_name ^ " type is not complete and cannot be used by RemotingProxy") p;
 			let eargs = [EArrayDecl (List.map (fun ((a,_),_,_,_,_) -> (EConst (Ident a),p)) fd.f_args),p] in
 			let ftype = (match fd.f_type with Some (CTPath { tpackage = []; tname = "Void" },_) -> None | _ -> fd.f_type) in
 			let fargs, eargs = if async then match ftype with
@@ -81,11 +81,11 @@ let extend_remoting ctx c t p async prot =
 	try
 		List.find (fun tdecl -> snd (t_path tdecl) = new_name) m.m_types
 	with Not_found ->
-		error ("Module " ^ s_type_path path ^ " does not define type " ^ t.tname) p
+		typing_error ("Module " ^ s_type_path path ^ " does not define type " ^ t.tname) p
 	) in
 	match t with
 	| TClassDecl c2 when c2.cl_params = [] -> ignore(c2.cl_build()); c.cl_super <- Some (c2,[]);
-	| _ -> error "Remoting proxy must be a class without parameters" p
+	| _ -> typing_error "Remoting proxy must be a class without parameters" p
 
 let on_inherit ctx c p (is_extends,tp) =
 	if not is_extends then

+ 22 - 22
src/typing/matcher.ml

@@ -68,9 +68,9 @@ let get_general_module_type ctx mt p =
 				| TInst(c,_) -> loop (TClassDecl c)
 				| TEnum(en,_) -> loop (TEnumDecl en)
 				| TAbstract(a,_) -> loop (TAbstractDecl a)
-				| _ -> error "Cannot use this type as a value" p
+				| _ -> typing_error "Cannot use this type as a value" p
 			end
-		| _ -> error "Cannot use this type as a value" p
+		| _ -> typing_error "Cannot use this type as a value" p
 	in
 	Typeload.load_instance ctx ({tname=loop mt;tpackage=[];tsub=None;tparams=[]},p) true
 
@@ -132,7 +132,7 @@ module Constructor = struct
 		| ConArray i -> make_int ctx.com.basic i p
 		| ConTypeExpr mt -> TyperBase.type_module_type ctx mt None p
 		| ConStatic(c,cf) -> make_static_field c cf p
-		| ConFields _ -> error "Something went wrong" p
+		| ConFields _ -> typing_error "Something went wrong" p
 
 	let hash con = Hashtbl.hash (fst con)
 end
@@ -183,18 +183,18 @@ module Pattern = struct
 		let ctx = pctx.ctx in
 		let p = pos e in
 		let fail () =
-			error ("Unrecognized pattern: " ^ (Ast.Printer.s_expr e)) p
+			typing_error ("Unrecognized pattern: " ^ (Ast.Printer.s_expr e)) p
 		in
 		let unify_expected t' =
 			unify ctx t' t p
 		in
 		let verror name p =
-			error (Printf.sprintf "Variable %s must appear exactly once in each sub-pattern" name) p
+			typing_error (Printf.sprintf "Variable %s must appear exactly once in each sub-pattern" name) p
 		in
 		let add_local final name p =
 			let is_wildcard_local = name = "_" in
-			if not is_wildcard_local && pctx.is_postfix_match then error "Pattern variables are not allowed in .match patterns" p;
-			if not is_wildcard_local && PMap.mem name pctx.current_locals then error (Printf.sprintf "Variable %s is bound multiple times" name) p;
+			if not is_wildcard_local && pctx.is_postfix_match then typing_error "Pattern variables are not allowed in .match patterns" p;
+			if not is_wildcard_local && PMap.mem name pctx.current_locals then typing_error (Printf.sprintf "Variable %s is bound multiple times" name) p;
 			match pctx.or_locals with
 			| Some map when not is_wildcard_local ->
 				let v,p = try PMap.find name map with Not_found -> verror name p in
@@ -344,7 +344,7 @@ module Pattern = struct
 				begin match follow t with
 					| TFun(ta,tr) when tr == fake_tuple_type ->
 						if i = "_" then PatTuple(List.map (fun (_,_,t) -> (PatAny,pos e)) ta)
-						else error "Cannot bind matched tuple to variable, use _ instead" p
+						else typing_error "Cannot bind matched tuple to variable, use _ instead" p
 					| _ ->
 						if i = "_" then PatAny
 						else handle_ident i (pos e)
@@ -377,9 +377,9 @@ module Pattern = struct
 							| [],[] ->
 								[]
 							| [],_ ->
-								error "Not enough arguments" p
+								typing_error "Not enough arguments" p
 							| _,[] ->
-								error "Too many arguments" p
+								typing_error "Too many arguments" p
 						in
 						let patterns = loop el args in
 						ignore(unapply_type_parameters ef.ef_params monos);
@@ -392,7 +392,7 @@ module Pattern = struct
 					try_typing e
 				with
 					| Exit -> fail()
-					| Bad_pattern s -> error s p
+					| Bad_pattern s -> typing_error s p
 				end
 			| EArrayDecl el ->
 				let rec pattern seen t = match follow t with
@@ -402,8 +402,8 @@ module Pattern = struct
 								let pat = make pctx false t e in
 								pat :: loop el tl
 							| [],[] -> []
-							| [],_ -> error "Not enough arguments" p
-							| (_,p) :: _,[] -> error "Too many arguments" p
+							| [],_ -> typing_error "Not enough arguments" p
+							| (_,p) :: _,[] -> typing_error "Too many arguments" p
 						in
 						let patterns = loop el tl in
 						PatTuple patterns
@@ -458,7 +458,7 @@ module Pattern = struct
 								collect_field cf (apply_params a.a_params tl cf.cf_type) filter
 						) c.cl_ordered_statics;
 					| _ ->
-						error (Printf.sprintf "Cannot field-match against %s" (s_type t)) (pos e)
+						typing_error (Printf.sprintf "Cannot field-match against %s" (s_type t)) (pos e)
 				in
 				collect_fields t None;
 				let is_matchable cf =
@@ -475,7 +475,7 @@ module Pattern = struct
 						else
 							patterns,fields
 				) ([],[]) !known_fields in
-				List.iter (fun ((s,_,_),e) -> if not (List.mem s fields) then error (Printf.sprintf "%s has no field %s" (s_type t) s) (pos e)) fl;
+				List.iter (fun ((s,_,_),e) -> if not (List.mem s fields) then typing_error (Printf.sprintf "%s has no field %s" (s_type t) s) (pos e)) fl;
 				PatConstructor(con_fields fields (pos e),patterns)
 			| EBinop(OpOr,e1,e2) ->
 				let pctx1 = {pctx with current_locals = PMap.empty} in
@@ -563,7 +563,7 @@ module Case = struct
 				let e2 = collapse_case el in
 				EBinop(OpOr,e,e2),punion (pos e) (pos e2)
 			| [] ->
-				error "case without pattern" p
+				typing_error "case without pattern" p
 		in
 		let e = collapse_case el in
 		let monos = List.map (fun _ -> mk_mono()) ctx.type_params in
@@ -1131,9 +1131,9 @@ module Compile = struct
 			| [],[] ->
 				bindings
 			| [],e :: _ ->
-				error "Invalid match: Not enough patterns" e.epos
+				typing_error "Invalid match: Not enough patterns" e.epos
 			| (_,p) :: _,[] ->
-				error "Invalid match: Too many patterns" p
+				typing_error "Invalid match: Too many patterns" p
 		in
 		let bindings = loop patterns subjects bindings in
 		if bindings = [] then dt else bind mctx (List.rev bindings) dt
@@ -1158,7 +1158,7 @@ module Compile = struct
 					| PatBind(v,pat1) -> loop ((v,pos pat,subject) :: bindings) pat1
 					| PatVariable _ | PatAny -> ()
 					| PatExtractor _ -> raise Extractor
-					| _ -> error ("Unexpected pattern: " ^ (Pattern.to_string pat)) case.case_pos;
+					| _ -> typing_error ("Unexpected pattern: " ^ (Pattern.to_string pat)) case.case_pos;
 				in
 				loop bindings (List.hd patterns)
 			) cases;
@@ -1419,7 +1419,7 @@ module TexprConverter = struct
 			| _ -> kind = SKValue
 		in
 		List.iter (fun (con,unguarded,dt) ->
-			if not (compatible_kind con) then error "Incompatible pattern" dt.dt_pos;
+			if not (compatible_kind con) then typing_error "Incompatible pattern" dt.dt_pos;
 			if unguarded then ConTable.remove h con
 		) cases;
 		let unmatched = ConTable.fold (fun con _ acc -> con :: acc) h [] in
@@ -1450,7 +1450,7 @@ module TexprConverter = struct
 			| [] -> "_"
 			| _ -> String.concat " | " (List.sort Pervasives.compare sl)
 		in
-		error (Printf.sprintf "Unmatched patterns: %s" (s_subject v_lookup s e_subject)) e_subject.epos
+		typing_error (Printf.sprintf "Unmatched patterns: %s" (s_subject v_lookup s e_subject)) e_subject.epos
 
 	type dt_recursion =
 		| Toplevel
@@ -1647,7 +1647,7 @@ module TexprConverter = struct
 		let e = loop Toplevel params dt in
 		match e with
 		| None ->
-			error "Unmatched patterns: _" p;
+			typing_error "Unmatched patterns: _" p;
 		| Some e ->
 			Texpr.duplicate_tvars e
 end

+ 21 - 21
src/typing/operators.ml

@@ -136,7 +136,7 @@ end
 let check_assign ctx e =
 	if ctx.com.display.dms_error_policy <> EPIgnore then match e.eexpr with
 	| TLocal v when has_var_flag v VFinal ->
-		error "Cannot assign to final" e.epos
+		typing_error "Cannot assign to final" e.epos
 	| TLocal {v_extra = None} | TArray _ | TField _ | TIdent _ ->
 		()
 	| TConst TThis | TTypeExpr _ when ctx.untyped ->
@@ -334,7 +334,7 @@ let make_binop ctx op e1 e2 is_assign_op with_type p =
 		| KOther, _
 		| _ , KOther ->
 			let pr = print_context() in
-			error ("Cannot add " ^ s_type pr e1.etype ^ " and " ^ s_type pr e2.etype) p
+			typing_error ("Cannot add " ^ s_type pr e1.etype ^ " and " ^ s_type pr e2.etype) p
 		)
 	| OpAnd
 	| OpOr
@@ -378,7 +378,7 @@ let make_binop ctx op e1 e2 is_assign_op with_type p =
 	| OpNotEq ->
 		let e1,e2 = try
 			(* we only have to check one type here, because unification fails if one is Void and the other is not *)
-			(match follow e2.etype with TAbstract({a_path=[],"Void"},_) -> error "Cannot compare Void" p | _ -> ());
+			(match follow e2.etype with TAbstract({a_path=[],"Void"},_) -> typing_error "Cannot compare Void" p | _ -> ());
 			AbstractCast.cast_or_unify_raise ctx e2.etype e1 p,e2
 		with Error (Unify _,_) ->
 			e1,AbstractCast.cast_or_unify ctx e1.etype e2 p
@@ -426,7 +426,7 @@ let make_binop ctx op e1 e2 is_assign_op with_type p =
 		| KOther , _
 		| _ , KOther ->
 			let pr = print_context() in
-			error ("Cannot compare " ^ s_type pr e1.etype ^ " and " ^ s_type pr e2.etype) p
+			typing_error ("Cannot compare " ^ s_type pr e1.etype ^ " and " ^ s_type pr e2.etype) p
 		);
 		mk_op e1 e2 ctx.t.tbool
 	| OpBoolAnd
@@ -441,9 +441,9 @@ let make_binop ctx op e1 e2 is_assign_op with_type p =
 		unify ctx e2.etype tint e2.epos;
 		BinopSpecial (mk (TNew ((match t with TInst (c,[]) -> c | _ -> die "" __LOC__),[],[e1;e2])) t p,false)
 	| OpArrow ->
-		error "Unexpected =>" p
+		typing_error "Unexpected =>" p
 	| OpIn ->
-		error "Unexpected in" p
+		typing_error "Unexpected in" p
 	| OpAssign
 	| OpAssignOp _ ->
 		die "" __LOC__
@@ -465,7 +465,7 @@ let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op with_type
 							()
 						| _ ->
 							let st = s_type (print_context()) in
-							error (Printf.sprintf "The result of this operation (%s) is not compatible with declared return type %s" (st t_expected) (st tret)) p
+							typing_error (Printf.sprintf "The result of this operation (%s) is not compatible with declared return type %s" (st t_expected) (st tret)) p
 				end;
 			end;
 			(*
@@ -602,18 +602,18 @@ let type_assign ctx e1 e2 with_type p =
 		let e2 = AbstractCast.cast_or_unify ctx e1.etype e2 p in
 		check_assign ctx e1;
 		(match e1.eexpr , e2.eexpr with
-		| TLocal i1 , TLocal i2 when i1 == i2 -> error "Assigning a value to itself" p
+		| TLocal i1 , TLocal i2 when i1 == i2 -> typing_error "Assigning a value to itself" p
 		| TField ({ eexpr = TConst TThis },FInstance (_,_,f1)) , TField ({ eexpr = TConst TThis },FInstance (_,_,f2)) when f1 == f2 ->
-			error "Assigning a value to itself" p
+			typing_error "Assigning a value to itself" p
 		| _ , _ -> ());
 		mk (TBinop (OpAssign,e1,e2)) e1.etype p
 	in
 	match e1 with
-	| AKNo s -> error ("Cannot access field or identifier " ^ s ^ " for writing") p
+	| AKNo s -> typing_error ("Cannot access field or identifier " ^ s ^ " for writing") p
 	| AKUsingField _ ->
-		error "Invalid operation" p
+		typing_error "Invalid operation" p
 	| AKExpr { eexpr = TLocal { v_kind = VUser TVOLocalFunction; v_name = name } } ->
-		error ("Cannot access function " ^ name ^ " for writing") p
+		typing_error ("Cannot access function " ^ name ^ " for writing") p
 	| AKField fa ->
 		let ef = FieldAccess.get_field_expr fa FWrite in
 		assign_to ef
@@ -632,7 +632,7 @@ let type_assign ctx e1 e2 with_type p =
 	| AKUsingAccessor sea ->
 		let fa_set = match FieldAccess.resolve_accessor sea.se_access (MSet (Some e2)) with
 			| AccessorFound fa -> fa
-			| _ -> error "Could not resolve accessor" p
+			| _ -> typing_error "Could not resolve accessor" p
 		in
 		let dispatcher = new call_dispatcher ctx (MCall [e2]) with_type p in
 		dispatcher#field_call fa_set [sea.se_this] [e2]
@@ -705,10 +705,10 @@ let type_assign_op ctx op e1 e2 with_type p =
 	| AKNo s ->
 		(* try abstract operator overloading *)
 		(try type_non_assign_op ctx op e1 e2 true true with_type p
-		with Not_found -> error ("Cannot access field or identifier " ^ s ^ " for writing") p
+		with Not_found -> typing_error ("Cannot access field or identifier " ^ s ^ " for writing") p
 		)
 	| AKUsingField _ ->
-		error "Invalid operation" p
+		typing_error "Invalid operation" p
 	| AKExpr e ->
 		let e,vr = process_lhs_expr ctx "lhs" e in
 		let e_rhs = type_binop2 ctx op e e2 true WithType.value p in
@@ -764,7 +764,7 @@ let type_assign_op ctx op e1 e2 with_type p =
 					| el -> mk (TBlock el) r_set p
 				end
 			| _ ->
-				error "Invalid array access getter/setter combination" p
+				typing_error "Invalid array access getter/setter combination" p
 		in
 		save();
 		vr#to_texpr	e
@@ -784,7 +784,7 @@ let type_binop ctx op e1 e2 is_assign_op with_type p =
 	| OpAssign ->
 		type_assign ctx e1 e2 with_type p
 	| OpAssignOp (OpBoolAnd | OpBoolOr) ->
-		error "The operators ||= and &&= are not supported" p
+		typing_error "The operators ||= and &&= are not supported" p
 	| OpAssignOp op ->
 		type_assign_op ctx op e1 e2 with_type p
 	| _ ->
@@ -827,7 +827,7 @@ let type_unop ctx op flag e with_type p =
 			raise Not_found
 	in
 	let unexpected_spread p =
-		error "Spread unary operator is only allowed for unpacking the last argument in a call with rest arguments" p
+		typing_error "Spread unary operator is only allowed for unpacking the last argument in a call with rest arguments" p
 	in
 	let make e =
 		let check_int () =
@@ -841,7 +841,7 @@ let type_unop ctx op flag e with_type p =
 		in
 		let t = match op with
 			| Not ->
-				if flag = Postfix then error "Postfix ! is not supported" p;
+				if flag = Postfix then typing_error "Postfix ! is not supported" p;
 				unify ctx e.etype ctx.t.tbool e.epos;
 				ctx.t.tbool
 			| NegBits ->
@@ -894,7 +894,7 @@ let type_unop ctx op flag e with_type p =
 		let access_set = !type_access_ref ctx (fst e) (snd e) (MSet None) WithType.value (* WITHTYPETODO *) in
 		match access_set with
 		| AKNo name ->
-			error ("The field or identifier " ^ name ^ " is not accessible for writing") p
+			typing_error ("The field or identifier " ^ name ^ " is not accessible for writing") p
 		| AKExpr e ->
 			find_overload_or_make e
 		| AKField fa ->
@@ -952,4 +952,4 @@ let type_unop ctx op flag e with_type p =
 				find_overload_or_make e
 			end
 		| AKUsingField _ | AKResolve _ ->
-			error "Invalid operation" p
+			typing_error "Invalid operation" p

+ 42 - 42
src/typing/typeload.ml

@@ -92,14 +92,14 @@ let find_type_in_module_raise ctx m tname p =
 			let infos = t_infos mt in
 			if snd infos.mt_path = tname then
 				if ctx.m.curmod != infos.mt_module && infos.mt_private then
-					raise_error (Type_not_found (m.m_path,tname,Private_type)) p
+					raise_typing_error (Type_not_found (m.m_path,tname,Private_type)) p
 				else
 					true
 			else
 				false
 		) m.m_types
 	with Not_found ->
-		raise_error (Type_not_found (m.m_path,tname,Not_defined)) p
+		raise_typing_error (Type_not_found (m.m_path,tname,Not_defined)) p
 
 (* raises Module_not_found or Type_not_found *)
 let load_type_raise ctx mpath tname p =
@@ -256,7 +256,7 @@ let is_redefined ctx cf1 fields p =
 		if not (type_iseq cf1.cf_type cf2.cf_type) then begin
 			display_error ctx ("Cannot redefine field " ^ cf1.cf_name ^ " with different type") p;
 			display_error ctx ("First type was " ^ (st cf1.cf_type)) cf1.cf_pos;
-			error ("Second type was " ^ (st cf2.cf_type)) cf2.cf_pos
+			typing_error ("Second type was " ^ (st cf2.cf_type)) cf2.cf_pos
 		end else
 			true
 	with Not_found ->
@@ -270,7 +270,7 @@ let make_extension_type ctx tl =
 				else fields
 			) a.a_fields fields
 		| _ ->
-			error "Can only extend structures" p
+			typing_error "Can only extend structures" p
 	in
 	let fields = List.fold_left mk_extension PMap.empty tl in
 	let tl = List.map (fun (t,_) -> t) tl in
@@ -305,7 +305,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 	let t = try
 		if t.tpackage <> [] || t.tsub <> None then raise Not_found;
 		let pt = List.assoc t.tname ctx.type_params in
-		if t.tparams <> [] then error ("Class type parameter " ^ t.tname ^ " can't have parameters") p;
+		if t.tparams <> [] then typing_error ("Class type parameter " ^ t.tname ^ " can't have parameters") p;
 		pt
 	with Not_found ->
 		let mt = load_type_def ctx p t in
@@ -336,7 +336,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 			match t.tparams with
 			| [] -> t_dynamic
 			| [TPType t] -> TDynamic (load_complex_type ctx true t)
-			| _ -> error "Too many parameters for Dynamic" p
+			| _ -> typing_error "Too many parameters for Dynamic" p
 		else begin
 			let is_java_rest = ctx.com.platform = Java && is_extern in
 			let is_rest = is_rest || is_java_rest in
@@ -367,9 +367,9 @@ let rec load_instance' ctx (t,p) allow_no_params =
 						let accepts_expression = name = "Rest" in
 						if is_expression then begin
 							if not expects_expression && not accepts_expression then
-								error "Constant value unexpected here" p
+								typing_error "Constant value unexpected here" p
 						end else if expects_expression then
-							error "Type parameter is expected to be a constant value" p
+							typing_error "Type parameter is expected to be a constant value" p
 					in
 					let is_rest = is_rest || name = "Rest" && is_generic_build in
 					let t = match follow t2 with
@@ -393,7 +393,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 					else if ctx.com.display.dms_error_policy = EPIgnore then
 						t :: loop [] tl is_rest
 					else
-						error ("Not enough type parameters for " ^ s_type_path path) p
+						typing_error ("Not enough type parameters for " ^ s_type_path path) p
 				| t :: tl,[] ->
 					let t,pt = load_param t in
 					if is_rest then
@@ -401,7 +401,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 					else if ctx.com.display.dms_error_policy = EPIgnore then
 						[]
 					else
-						error ("Too many type parameters for " ^ s_type_path path) pt
+						typing_error ("Too many type parameters for " ^ s_type_path path) pt
 			in
 			let params = loop t.tparams types false in
 			if not is_rest then begin
@@ -444,8 +444,8 @@ and load_complex_type' ctx allow_display (t,p) =
 	| CTParent t -> load_complex_type ctx allow_display t
 	| CTPath { tpackage = ["$"]; tname = "_hx_mono" } -> spawn_monomorph ctx p
 	| CTPath t -> load_instance ~allow_display ctx (t,p) false
-	| CTOptional _ -> error "Optional type not allowed here" p
-	| CTNamed _ -> error "Named type not allowed here" p
+	| CTOptional _ -> typing_error "Optional type not allowed here" p
+	| CTNamed _ -> typing_error "Named type not allowed here" p
 	| CTIntersection tl ->
 		let tl = List.map (fun (t,pn) ->
 			try
@@ -472,13 +472,13 @@ and load_complex_type' ctx allow_display (t,p) =
 			let mk_extension (t,p) =
 				match follow t with
 				| TInst ({cl_kind = KTypeParameter _},_) ->
-					error "Cannot structurally extend type parameters" p
+					typing_error "Cannot structurally extend type parameters" p
 				| TMono _ ->
-					error "Loop found in cascading signatures definitions. Please change order/import" p
+					typing_error "Loop found in cascading signatures definitions. Please change order/import" p
 				| TAnon a2 ->
 					PMap.iter (fun _ cf -> ignore(is_redefined ctx cf a2.a_fields p)) a.a_fields;
 					mk_anon ~fields:(PMap.foldi PMap.add a.a_fields a2.a_fields) (ref (Extend [t]))
-				| _ -> error "Can only extend structures" p
+				| _ -> typing_error "Can only extend structures" p
 			in
 			let loop (t,p) = match follow t with
 				| TAnon a2 ->
@@ -487,7 +487,7 @@ and load_complex_type' ctx allow_display (t,p) =
 							a.a_fields <- PMap.add f cf a.a_fields
 					) a2.a_fields
 				| _ ->
-					error "Can only extend structures" p
+					typing_error "Can only extend structures" p
 			in
 			let il = List.map (fun (t,pn) ->
 				try
@@ -520,15 +520,15 @@ and load_complex_type' ctx allow_display (t,p) =
 		let rec loop acc f =
 			let n = fst f.cff_name in
 			let p = f.cff_pos in
-			if PMap.mem n acc then error ("Duplicate field declaration : " ^ n) p;
+			if PMap.mem n acc then typing_error ("Duplicate field declaration : " ^ n) p;
 			let topt = function
-				| None -> error ("Explicit type required for field " ^ n) p
+				| None -> typing_error ("Explicit type required for field " ^ n) p
 				| Some t -> load_complex_type ctx allow_display t
 			in
 			if n = "new" then ctx.com.warning "Structures with new are deprecated, use haxe.Constraints.Constructible instead" p;
 			let no_expr = function
 				| None -> ()
-				| Some (_,p) -> error "Expression not allowed here" p
+				| Some (_,p) -> typing_error "Expression not allowed here" p
 			in
 			let pub = ref true in
 			let dyn = ref false in
@@ -545,15 +545,15 @@ and load_complex_type' ctx allow_display (t,p) =
 					pub := false;
 				| ADynamic when (match f.cff_kind with FFun _ -> true | _ -> false) -> dyn := true
 				| AFinal -> final := true
-				| AStatic | AOverride | AInline | ADynamic | AMacro | AExtern | AAbstract | AOverload as a -> error ("Invalid access " ^ Ast.s_access a) p
+				| AStatic | AOverride | AInline | ADynamic | AMacro | AExtern | AAbstract | AOverload as a -> typing_error ("Invalid access " ^ Ast.s_access a) p
 			) f.cff_access;
 			let t , access = (match f.cff_kind with
 				| FVar(t,e) when !final ->
 					no_expr e;
-					let t = (match t with None -> error "Type required for structure property" p | Some t -> t) in
+					let t = (match t with None -> typing_error "Type required for structure property" p | Some t -> t) in
 					load_complex_type ctx allow_display t, Var { v_read = AccNormal; v_write = AccNever }
 				| FVar (Some (CTPath({tpackage=[];tname="Void"}),_), _)  | FProp (_,_,Some (CTPath({tpackage=[];tname="Void"}),_),_) ->
-					error "Fields of type Void are not allowed in structures" p
+					typing_error "Fields of type Void are not allowed in structures" p
 				| FVar (t, e) ->
 					no_expr e;
 					topt t, Var { v_read = AccNormal; v_write = AccNormal }
@@ -579,9 +579,9 @@ and load_complex_type' ctx allow_display (t,p) =
 						| x when get && x = "get_" ^ n -> AccCall
 						| x when not get && x = "set_" ^ n -> AccCall
 						| _ ->
-							error "Custom property access is no longer supported in Haxe 3" f.cff_pos;
+							typing_error "Custom property access is no longer supported in Haxe 3" f.cff_pos;
 					in
-					let t = (match t with None -> error "Type required for structure property" p | Some t -> t) in
+					let t = (match t with None -> typing_error "Type required for structure property" p | Some t -> t) in
 					load_complex_type ctx allow_display t, Var { v_read = access i1 true; v_write = access i2 false }
 			) in
 			let t = if Meta.has Meta.Optional f.cff_meta then ctx.t.tnull t else t in
@@ -641,10 +641,10 @@ and init_meta_overloads ctx co cf =
 	cf.cf_meta <- List.filter (fun m ->
 		match m with
 		| (Meta.Overload,[(EFunction (kind,f),p)],_)  ->
-			(match kind with FKNamed _ -> error "Function name must not be part of @:overload" p | _ -> ());
-			(match f.f_expr with Some (EBlock [], _) -> () | _ -> error "Overload must only declare an empty method body {}" p);
+			(match kind with FKNamed _ -> typing_error "Function name must not be part of @:overload" p | _ -> ());
+			(match f.f_expr with Some (EBlock [], _) -> () | _ -> typing_error "Overload must only declare an empty method body {}" p);
 			(match cf.cf_kind with
-				| Method MethInline -> error "Cannot @:overload inline function" p
+				| Method MethInline -> typing_error "Cannot @:overload inline function" p
 				| _ -> ());
 			let old = ctx.type_params in
 			(match cf.cf_params with
@@ -652,7 +652,7 @@ and init_meta_overloads ctx co cf =
 			| l -> ctx.type_params <- List.filter (fun t -> not (List.mem t l)) ctx.type_params);
 			let params = (!type_function_params_rec) ctx f cf.cf_name p in
 			ctx.type_params <- params @ ctx.type_params;
-			let topt = function None -> error "Explicit type required" p | Some t -> load_complex_type ctx true t in
+			let topt = function None -> typing_error "Explicit type required" p | Some t -> load_complex_type ctx true t in
 			let args =
 				List.map
 					(fun ((a,_),opt,_,t,cto) ->
@@ -669,15 +669,15 @@ and init_meta_overloads ctx co cf =
 			false
 		| (Meta.Overload,[],_) when ctx.com.config.pf_overload ->
 			add_class_field_flag cf CfOverload;
-			let topt (n,_,t) = match t with | TMono t when t.tm_type = None -> error ("Explicit type required for overload functions\n... For function argument '" ^ n ^ "'") cf.cf_pos | _ -> () in
+			let topt (n,_,t) = match t with | TMono t when t.tm_type = None -> typing_error ("Explicit type required for overload functions\n... For function argument '" ^ n ^ "'") cf.cf_pos | _ -> () in
 			(match follow cf.cf_type with
 			| TFun (args,_) -> List.iter topt args
 			| _ -> () (* could be a variable *));
 			true
 		| (Meta.Overload,[],p) ->
-				error "This platform does not support this kind of overload declaration. Try @:overload(function()... {}) instead" p
+			typing_error "This platform does not support this kind of overload declaration. Try @:overload(function()... {}) instead" p
 		| (Meta.Overload,_,p) ->
-				error "Invalid @:overload metadata format" p
+			typing_error "Invalid @:overload metadata format" p
 		| _ ->
 			true
 	) cf.cf_meta;
@@ -801,7 +801,7 @@ let rec type_type_param ?(enum_constructor=false) ctx path get_params p tp =
 			(* check against direct recursion *)
 			let rec loop t =
 				match follow t with
-				| TInst (c2,_) when c == c2 -> error "Recursive constraint parameter is not allowed" p
+				| TInst (c2,_) when c == c2 -> typing_error "Recursive constraint parameter is not allowed" p
 				| TInst ({ cl_kind = KTypeParameter cl },_) ->
 					List.iter loop cl
 				| _ ->
@@ -860,7 +860,7 @@ let init_core_api ctx c =
 					List.iter2 (fun t1 t2 -> type_eq EqCoreType t2 t1) l1 l2
 				with
 					| Invalid_argument _ ->
-						error "Type parameters must have the same number of constraints as core type" c.cl_pos
+						typing_error "Type parameters must have the same number of constraints as core type" c.cl_pos
 					| Unify_error l ->
 						display_error ctx ("Type parameter " ^ n2 ^ " has different constraint than in core type") c.cl_pos;
 						display_error ctx (error_msg (Unify l)) c.cl_pos
@@ -870,7 +870,7 @@ let init_core_api ctx c =
 				die "" __LOC__
 		) ccore.cl_params c.cl_params;
 	with Invalid_argument _ ->
-		error "Class must have the same number of type parameters as core type" c.cl_pos
+		typing_error "Class must have the same number of type parameters as core type" c.cl_pos
 	end;
 	(match c.cl_doc with
 	| None -> c.cl_doc <- ccore.cl_doc
@@ -882,7 +882,7 @@ let init_core_api ctx c =
 		with Unify_error l ->
 			display_error ctx ("Field " ^ f.cf_name ^ " has different type than in core type") p;
 			display_error ctx (error_msg (Unify l)) p);
-		if (has_class_field_flag f2 CfPublic) <> (has_class_field_flag f CfPublic) then error ("Field " ^ f.cf_name ^ " has different visibility than core type") p;
+		if (has_class_field_flag f2 CfPublic) <> (has_class_field_flag f CfPublic) then typing_error ("Field " ^ f.cf_name ^ " has different visibility than core type") p;
 		(match f2.cf_doc with
 		| None -> f2.cf_doc <- f.cf_doc
 		| Some _ -> ());
@@ -891,25 +891,25 @@ let init_core_api ctx c =
 			| Method MethInline, Method MethNormal -> () (* allow to add 'inline' *)
 			| Method MethNormal, Method MethInline -> () (* allow to disable 'inline' *)
 			| _ ->
-				error ("Field " ^ f.cf_name ^ " has different property access than core type") p;
+				typing_error ("Field " ^ f.cf_name ^ " has different property access than core type") p;
 		end;
 		(match follow f.cf_type, follow f2.cf_type with
 		| TFun (pl1,_), TFun (pl2,_) ->
-			if List.length pl1 != List.length pl2 then error "Argument count mismatch" p;
+			if List.length pl1 != List.length pl2 then typing_error "Argument count mismatch" p;
 			List.iter2 (fun (n1,_,_) (n2,_,_) ->
-				if n1 <> n2 then error ("Method parameter name '" ^ n2 ^ "' should be '" ^ n1 ^ "'") p;
+				if n1 <> n2 then typing_error ("Method parameter name '" ^ n2 ^ "' should be '" ^ n1 ^ "'") p;
 			) pl1 pl2;
 		| _ -> ());
 	in
 	let check_fields fcore fl =
 		PMap.iter (fun i f ->
 			if not (has_class_field_flag f CfPublic) then () else
-			let f2 = try PMap.find f.cf_name fl with Not_found -> error ("Missing field " ^ i ^ " required by core type") c.cl_pos in
+			let f2 = try PMap.find f.cf_name fl with Not_found -> typing_error ("Missing field " ^ i ^ " required by core type") c.cl_pos in
 			compare_fields f f2;
 		) fcore;
 		PMap.iter (fun i f ->
 			let p = (match f.cf_expr with None -> c.cl_pos | Some e -> e.epos) in
-			if (has_class_field_flag f CfPublic) && not (Meta.has Meta.Hack f.cf_meta) && not (PMap.mem f.cf_name fcore) && not (has_class_field_flag f CfOverride) then error ("Public field " ^ i ^ " is not part of core type") p;
+			if (has_class_field_flag f CfPublic) && not (Meta.has Meta.Hack f.cf_meta) && not (PMap.mem f.cf_name fcore) && not (has_class_field_flag f CfOverride) then typing_error ("Public field " ^ i ^ " is not part of core type") p;
 		) fl;
 	in
 	check_fields ccore.cl_fields c.cl_fields;
@@ -919,11 +919,11 @@ let init_core_api ctx c =
 	| Some cf, _ when not (has_class_field_flag cf CfPublic) -> ()
 	| Some f, Some f2 -> compare_fields f f2
 	| None, Some cf when not (has_class_field_flag cf CfPublic) -> ()
-	| _ -> error "Constructor differs from core type" c.cl_pos)
+	| _ -> typing_error "Constructor differs from core type" c.cl_pos)
 
 let string_list_of_expr_path (e,p) =
 	try string_list_of_expr_path_raise (e,p)
-	with Exit -> error "Invalid path" p
+	with Exit -> typing_error "Invalid path" p
 
 let handle_using ctx path p =
 	let t = match List.rev path with

+ 18 - 18
src/typing/typeloadCheck.ml

@@ -146,7 +146,7 @@ let get_native_name meta =
 	| [] ->
 		raise Not_found
 	| _ ->
-		error "String expected" mp
+		typing_error "String expected" mp
 
 let check_native_name_override ctx child base =
 	let error base_pos child_pos =
@@ -322,8 +322,8 @@ let check_module_types ctx m p t =
 	let t = t_infos t in
 	try
 		let m2 = Hashtbl.find ctx.g.types_module t.mt_path in
-		if m.m_path <> m2 && String.lowercase (s_type_path m2) = String.lowercase (s_type_path m.m_path) then error ("Module " ^ s_type_path m2 ^ " is loaded with a different case than " ^ s_type_path m.m_path) p;
-		error ("Type name " ^ s_type_path t.mt_path ^ " is redefined from module " ^ s_type_path m2) p
+		if m.m_path <> m2 && String.lowercase (s_type_path m2) = String.lowercase (s_type_path m.m_path) then typing_error ("Module " ^ s_type_path m2 ^ " is loaded with a different case than " ^ s_type_path m.m_path) p;
+		typing_error ("Type name " ^ s_type_path t.mt_path ^ " is redefined from module " ^ s_type_path m2) p
 	with
 		Not_found ->
 			Hashtbl.add ctx.g.types_module t.mt_path m.m_path
@@ -335,15 +335,15 @@ module Inheritance = struct
 
 	let check_extends ctx c t p = match follow t with
 		| TInst (csup,params) ->
-			if is_basic_class_path csup.cl_path && not ((has_class_flag c CExtern) && (has_class_flag csup CExtern)) then error "Cannot extend basic class" p;
-			if extends csup c then error "Recursive class" p;
+			if is_basic_class_path csup.cl_path && not ((has_class_flag c CExtern) && (has_class_flag csup CExtern)) then typing_error "Cannot extend basic class" p;
+			if extends csup c then typing_error "Recursive class" p;
 			begin match csup.cl_kind with
 				| KTypeParameter _ ->
-					if is_generic_parameter ctx csup then error "Extending generic type parameters is no longer allowed in Haxe 4" p;
-					error "Cannot extend type parameters" p
+					if is_generic_parameter ctx csup then typing_error "Extending generic type parameters is no longer allowed in Haxe 4" p;
+					typing_error "Cannot extend type parameters" p
 				| _ -> csup,params
 			end
-		| _ -> error "Should extend by using a class" p
+		| _ -> typing_error "Should extend by using a class" p
 
 	let rec check_interface ctx missing c intf params =
 		List.iter (fun (i2,p2) ->
@@ -499,7 +499,7 @@ module Inheritance = struct
 				| _ -> ()
 			) csup.cl_meta;
 			if has_class_flag csup CFinal && not (((has_class_flag csup CExtern) && Meta.has Meta.Hack c.cl_meta) || (match c.cl_kind with KTypeParameter _ -> true | _ -> false)) then
-				error ("Cannot extend a final " ^ if (has_class_flag c CInterface) then "interface" else "class") p;
+				typing_error ("Cannot extend a final " ^ if (has_class_flag c CInterface) then "interface" else "class") p;
 		in
 		let check_cancel_build csup =
 			match csup.cl_build() with
@@ -541,17 +541,17 @@ module Inheritance = struct
 		(* Pass 1: Check and set relations *)
 		let check_herit t is_extends p =
 			if is_extends then begin
-				if c.cl_super <> None then error "Cannot extend several classes" p;
+				if c.cl_super <> None then typing_error "Cannot extend several classes" p;
 				let csup,params = check_extends ctx c t p in
 				if (has_class_flag c CInterface) then begin
-					if not (has_class_flag csup CInterface) then error "Cannot extend by using a class" p;
+					if not (has_class_flag csup CInterface) then typing_error "Cannot extend by using a class" p;
 					c.cl_implements <- (csup,params) :: c.cl_implements;
 					if not !has_interf then begin
 						if not is_lib then delay ctx PConnectField (fun() -> check_interfaces ctx c);
 						has_interf := true;
 					end
 				end else begin
-					if (has_class_flag csup CInterface) then error "Cannot extend by using an interface" p;
+					if (has_class_flag csup CInterface) then typing_error "Cannot extend by using an interface" p;
 					c.cl_super <- Some (csup,params)
 				end;
 				(fun () ->
@@ -560,13 +560,13 @@ module Inheritance = struct
 				)
 			end else begin match follow t with
 				| TInst ({ cl_path = [],"ArrayAccess" } as ca,[t]) when (has_class_flag ca CExtern) ->
-					if c.cl_array_access <> None then error "Duplicate array access" p;
+					if c.cl_array_access <> None then typing_error "Duplicate array access" p;
 					c.cl_array_access <- Some t;
 					(fun () -> ())
 				| TInst (intf,params) ->
-					if extends intf c then error "Recursive class" p;
-					if (has_class_flag c CInterface) then error "Interfaces cannot implement another interface (use extends instead)" p;
-					if not (has_class_flag intf CInterface) then error "You can only implement an interface" p;
+					if extends intf c then typing_error "Recursive class" p;
+					if (has_class_flag c CInterface) then typing_error "Interfaces cannot implement another interface (use extends instead)" p;
+					if not (has_class_flag intf CInterface) then typing_error "You can only implement an interface" p;
 					c.cl_implements <- (intf, params) :: c.cl_implements;
 					if not !has_interf && not is_lib && not (Meta.has (Meta.Custom "$do_not_check_interf") c.cl_meta) then begin
 						delay ctx PConnectField (fun() -> check_interfaces ctx c);
@@ -577,12 +577,12 @@ module Inheritance = struct
 						process_meta intf;
 					)
 				| TDynamic t ->
-					if c.cl_dynamic <> None then error "Cannot have several dynamics" p;
+					if c.cl_dynamic <> None then typing_error "Cannot have several dynamics" p;
 					if not (has_class_flag c CExtern) then display_error ctx "In haxe 4, implements Dynamic is only supported on externs" p;
 					c.cl_dynamic <- Some t;
 					(fun () -> ())
 				| _ ->
-					error "Should implement by using an interface" p
+					typing_error "Should implement by using an interface" p
 			end
 		in
 		let fl = ExtList.List.filter_map (fun (is_extends,(ct,p)) ->

+ 59 - 59
src/typing/typeloadFields.ml

@@ -240,20 +240,20 @@ let transform_abstract_field com this_t a_t a f =
 	| FProp ((("get" | "never"),_),(("set" | "never"),_),_,_) when not stat ->
 		f
 	| FProp _ when not stat && not (Meta.has Meta.Enum f.cff_meta) ->
-		error "Member property accessors must be get/set or never" p;
+		typing_error "Member property accessors must be get/set or never" p;
 	| FFun fu when fst f.cff_name = "new" && not stat ->
 		let init p = (EVars [mk_evar ~t:this_t ("this",null_pos)],p) in
 		let cast e = (ECast(e,None)),pos e in
 		let ret p = (EReturn (Some (cast (EConst (Ident "this"),p))),p) in
 		let meta = (Meta.NoCompletion,[],null_pos) :: f.cff_meta in
 		if Meta.has Meta.MultiType a.a_meta then begin
-			if List.mem_assoc AInline f.cff_access then error "MultiType constructors cannot be inline" f.cff_pos;
-			if fu.f_expr <> None then error "MultiType constructors cannot have a body" f.cff_pos;
+			if List.mem_assoc AInline f.cff_access then typing_error "MultiType constructors cannot be inline" f.cff_pos;
+			if fu.f_expr <> None then typing_error "MultiType constructors cannot have a body" f.cff_pos;
 			f.cff_access <- (AExtern,null_pos) :: f.cff_access;
 		end;
 		(try
 			let _, p = List.find (fun (acc, _) -> acc = AMacro) f.cff_access in
-			error "Macro abstract constructors are not supported" p
+			typing_error "Macro abstract constructors are not supported" p
 		with Not_found -> ());
 		(* We don't want the generated expression positions to shadow the real code. *)
 		let p = { p with pmax = p.pmin } in
@@ -268,7 +268,7 @@ let transform_abstract_field com this_t a_t a f =
 		} in
 		{ f with cff_name = "_new",pos f.cff_name; cff_kind = FFun fu; cff_meta = meta }
 	| FFun fu when not stat ->
-		if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;
+		if Meta.has Meta.From f.cff_meta then typing_error "@:from cast functions must be static" f.cff_pos;
 		{ f with cff_kind = FFun fu }
 	| _ ->
 		f
@@ -420,7 +420,7 @@ let build_enum_abstract ctx c a fields p =
 							set_field field ct (EConst (Int (string_of_int !i)),null_pos);
 							incr i;
 						| EAOther ->
-							error "Value required" field.cff_pos
+							typing_error "Value required" field.cff_pos
 					end else field.cff_kind <- FProp(("default",null_pos),("never",null_pos),ct,None)
 				| Some e ->
 					begin match mode,e with
@@ -443,7 +443,7 @@ let build_enum_abstract ctx c a fields p =
 let apply_macro ctx mode path el p =
 	let cpath, meth = (match List.rev (ExtString.String.nsplit path ".") with
 		| meth :: name :: pack -> (List.rev pack,name), meth
-		| _ -> error "Invalid macro path" p
+		| _ -> typing_error "Invalid macro path" p
 	) in
 	ctx.g.do_macro ctx mode cpath meth el p
 
@@ -453,17 +453,17 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 		| Meta.Build,args,p when not is_typedef -> (fun () ->
 				let epath, el = (match args with
 					| [ECall (epath,el),p] -> epath, el
-					| _ -> error "Invalid build parameters" p
+					| _ -> typing_error "Invalid build parameters" p
 				) in
-				let s = try String.concat "." (List.rev (string_list_of_expr_path epath)) with Error (_,p) -> error "Build call parameter must be a class path" p in
-				if ctx.in_macro then error "You cannot use @:build inside a macro : make sure that your type is not used in macro" p;
+				let s = try String.concat "." (List.rev (string_list_of_expr_path epath)) with Error (_,p) -> typing_error "Build call parameter must be a class path" p in
+				if ctx.in_macro then typing_error "You cannot use @:build inside a macro : make sure that your type is not used in macro" p;
 				let old = ctx.get_build_infos in
 				ctx.get_build_infos <- (fun() -> Some (mt, List.map snd (t_infos mt).mt_params, fvars()));
 				context_init#run;
 				let r = try apply_macro ctx MBuild s el p with e -> ctx.get_build_infos <- old; raise e in
 				ctx.get_build_infos <- old;
 				(match r with
-				| None -> error "Build failure" p
+				| None -> typing_error "Build failure" p
 				| Some e -> fbuild e)
 			) :: f_build
 		| Meta.Using,el,p -> (fun () ->
@@ -478,7 +478,7 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 					in
 					ti.mt_using <- (filter_classes types) @ ti.mt_using;
 				with Exit ->
-					error "dot path expected" (pos e)
+					typing_error "dot path expected" (pos e)
 			) el;
 		) :: f_build
 		| _ ->
@@ -670,7 +670,7 @@ let transform_field (ctx,cctx) c f fields p =
 		| Some (_,mctx) when Hashtbl.mem mctx.g.types_module c.cl_path ->
 			(* assume that if we had already a macro with the same name, it has not been changed during the @:build operation *)
 			if not (List.exists (fun f2 -> f2.cff_name = f.cff_name && List.mem_assoc AMacro f2.cff_access) (!fields)) then
-				error "Class build macro cannot return a macro function when the class has already been compiled into the macro context" p
+				typing_error "Class build macro cannot return a macro function when the class has already been compiled into the macro context" p
 		| _ -> ());
 	f
 
@@ -697,7 +697,7 @@ let build_fields (ctx,cctx) c fields =
 		| EVars [{ ev_type = Some (CTAnonymous f,p); ev_expr = None }] ->
 			let f = List.map (fun f -> transform_field (ctx,cctx) c f fields p) f in
 			fields := f
-		| _ -> error "Class build macro must return a single variable with anonymous fields" p
+		| _ -> typing_error "Class build macro must return a single variable with anonymous fields" p
 	);
 	c.cl_build <- (fun() -> Building [c]);
 	List.iter (fun f -> f()) !pending;
@@ -954,19 +954,19 @@ end
 
 let create_variable (ctx,cctx,fctx) c f t eo p =
 	let is_abstract_enum_field = Meta.has Meta.Enum f.cff_meta in
-	if fctx.is_abstract_member && not is_abstract_enum_field then error (fst f.cff_name ^ ": Cannot declare member variable in abstract") p;
-	if fctx.is_inline && not fctx.is_static then error (fst f.cff_name ^ ": Inline variable must be static") p;
-	if fctx.is_inline && eo = None then error (fst f.cff_name ^ ": Inline variable must be initialized") p;
+	if fctx.is_abstract_member && not is_abstract_enum_field then typing_error (fst f.cff_name ^ ": Cannot declare member variable in abstract") p;
+	if fctx.is_inline && not fctx.is_static then typing_error (fst f.cff_name ^ ": Inline variable must be static") p;
+	if fctx.is_inline && eo = None then typing_error (fst f.cff_name ^ ": Inline variable must be initialized") p;
 	let missing_initialization =
 		fctx.is_final
 		&& not (fctx.is_extern || (has_class_flag c CExtern) || (has_class_flag c CInterface))
 		&& eo = None
 	in
 	if missing_initialization && fctx.is_static && fctx.is_final then
-		error (fst f.cff_name ^ ": Static final variable must be initialized") p;
+		typing_error (fst f.cff_name ^ ": Static final variable must be initialized") p;
 	let t = (match t with
 		| None when eo = None ->
-			error ("Variable requires type-hint or initialization") (pos f.cff_name);
+			typing_error ("Variable requires type-hint or initialization") (pos f.cff_name);
 		| None ->
 			mk_mono()
 		| Some t ->
@@ -1017,15 +1017,15 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					let r = exc_protect ctx (fun r ->
 						r := lazy_processing (fun () -> t);
 						(* the return type of a from-function must be the abstract, not the underlying type *)
-						if not fctx.is_macro then (try type_eq EqStrict ret ta with Unify_error l -> error (error_msg (Unify l)) p);
+						if not fctx.is_macro then (try type_eq EqStrict ret ta with Unify_error l -> typing_error (error_msg (Unify l)) p);
 						match t with
 							| TFun([_,_,t],_) -> t
 							| TFun([(_,_,t1);(_,true,t2)],_) when is_pos_infos t2 -> t1
-							| _ -> error (cf.cf_name ^ ": @:from cast functions must accept exactly one argument") p
+							| _ -> typing_error (cf.cf_name ^ ": @:from cast functions must accept exactly one argument") p
 					) "@:from" in
 					a.a_from_field <- (TLazy r,cf) :: a.a_from_field;
 				| (Meta.To,_,_) :: _ ->
-					if fctx.is_macro then error (cf.cf_name ^ ": Macro cast functions are not supported") p;
+					if fctx.is_macro then typing_error (cf.cf_name ^ ": Macro cast functions are not supported") p;
 					let are_valid_args args =
 						match args with
 						| [_] -> true
@@ -1034,19 +1034,19 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					in
 					(match cf.cf_kind, cf.cf_type with
 					| Var _, _ ->
-						error "@:to meta should be used on methods" p
+						typing_error "@:to meta should be used on methods" p
 					| Method _, TFun(args, _) when not fctx.is_abstract_member && not (are_valid_args args) ->
 						if not (Meta.has Meta.MultiType a.a_meta) then (* TODO: get rid of this check once multitype is removed *)
-						error ("static @:to method should have one argument") p
+						typing_error ("static @:to method should have one argument") p
 					| Method _, TFun(args, _) when fctx.is_abstract_member && not (are_valid_args args) ->
 						if not (Meta.has Meta.MultiType a.a_meta) then (* TODO: get rid of this check once multitype is removed *)
-						error "@:to method should have no arguments" p
+						typing_error "@:to method should have no arguments" p
 					| _ -> ()
 					);
 					(* TODO: this doesn't seem quite right... *)
 					if not (has_class_field_flag cf CfImpl) then add_class_field_flag cf CfImpl;
 					let resolve_m args =
-						(try unify_raise ctx t (tfun (tthis :: args) m) cf.cf_pos with Error (Unify l,p) -> error (error_msg (Unify l)) p);
+						(try unify_raise ctx t (tfun (tthis :: args) m) cf.cf_pos with Error (Unify l,p) -> typing_error (error_msg (Unify l)) p);
 						match follow m with
 							| TMono _ when (match t with TFun(_,r) -> r == t_dynamic | _ -> false) -> t_dynamic
 							| m -> m
@@ -1060,7 +1060,7 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 							let ctor = try
 								PMap.find "_new" c.cl_statics
 							with Not_found ->
-								error "Constructor of multi-type abstract must be defined before the individual @:to-functions are" cf.cf_pos
+								typing_error "Constructor of multi-type abstract must be defined before the individual @:to-functions are" cf.cf_pos
 							in
 							(* delay ctx PFinal (fun () -> unify ctx m tthis f.cff_pos); *)
 							let args = match follow (monomorphs a.a_params ctor.cf_type) with
@@ -1078,15 +1078,15 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					) "@:to" in
 					a.a_to_field <- (TLazy r, cf) :: a.a_to_field
 				| ((Meta.ArrayAccess,_,_) | (Meta.Op,[(EArrayDecl _),_],_)) :: _ ->
-					if fctx.is_macro then error (cf.cf_name ^ ": Macro array-access functions are not supported") p;
+					if fctx.is_macro then typing_error (cf.cf_name ^ ": Macro array-access functions are not supported") p;
 					a.a_array <- cf :: a.a_array;
 					allow_no_expr();
 				| (Meta.Op,[EBinop(OpAssign,_,_),_],_) :: _ ->
-					error (cf.cf_name ^ ": Assignment overloading is not supported") p;
+					typing_error (cf.cf_name ^ ": Assignment overloading is not supported") p;
 				| (Meta.Op,[ETernary(_,_,_),_],_) :: _ ->
-					error (cf.cf_name ^ ": Ternary overloading is not supported") p;
+					typing_error (cf.cf_name ^ ": Ternary overloading is not supported") p;
 				| (Meta.Op,[EBinop(op,_,_),_],_) :: _ ->
-					if fctx.is_macro then error (cf.cf_name ^ ": Macro operator functions are not supported") p;
+					if fctx.is_macro then typing_error (cf.cf_name ^ ": Macro operator functions are not supported") p;
 					let targ = if fctx.is_abstract_member then tthis else ta in
 					let left_eq,right_eq =
 						match follow t with
@@ -1096,16 +1096,16 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 							type_iseq targ t1,type_iseq targ t2
 						| _ ->
 							if fctx.is_abstract_member then
-								error (cf.cf_name ^ ": Member @:op functions must accept exactly one argument") cf.cf_pos
+								typing_error (cf.cf_name ^ ": Member @:op functions must accept exactly one argument") cf.cf_pos
 							else
-								error (cf.cf_name ^ ": Static @:op functions must accept exactly two arguments") cf.cf_pos
+								typing_error (cf.cf_name ^ ": Static @:op functions must accept exactly two arguments") cf.cf_pos
 					in
-					if not (left_eq || right_eq) then error (cf.cf_name ^ ": The left or right argument type must be " ^ (s_type (print_context()) targ)) cf.cf_pos;
-					if right_eq && Meta.has Meta.Commutative cf.cf_meta then error (cf.cf_name ^ ": @:commutative is only allowed if the right argument is not " ^ (s_type (print_context()) targ)) cf.cf_pos;
+					if not (left_eq || right_eq) then typing_error (cf.cf_name ^ ": The left or right argument type must be " ^ (s_type (print_context()) targ)) cf.cf_pos;
+					if right_eq && Meta.has Meta.Commutative cf.cf_meta then typing_error (cf.cf_name ^ ": @:commutative is only allowed if the right argument is not " ^ (s_type (print_context()) targ)) cf.cf_pos;
 					a.a_ops <- (op,cf) :: a.a_ops;
 					allow_no_expr();
 				| (Meta.Op,[EUnop(op,flag,_),_],_) :: _ ->
-					if fctx.is_macro then error (cf.cf_name ^ ": Macro operator functions are not supported") p;
+					if fctx.is_macro then typing_error (cf.cf_name ^ ": Macro operator functions are not supported") p;
 					let targ = if fctx.is_abstract_member then tthis else ta in
 					(try type_eq EqStrict t (tfun [targ] (mk_mono())) with Unify_error l -> raise (Error ((Unify l),cf.cf_pos)));
 					a.a_unops <- (op,flag,cf) :: a.a_unops;
@@ -1122,21 +1122,21 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					let targ = if fctx.is_abstract_member then tthis else ta in
 					let check_fun t1 t2 =
 						if not fctx.is_macro then begin
-							if not (type_iseq targ t1) then error ("First argument type must be " ^ (s_type (print_context()) targ)) cf.cf_pos;
-							if not (type_iseq ctx.t.tstring t2) then error ("Second argument type must be String") cf.cf_pos
+							if not (type_iseq targ t1) then typing_error ("First argument type must be " ^ (s_type (print_context()) targ)) cf.cf_pos;
+							if not (type_iseq ctx.t.tstring t2) then typing_error ("Second argument type must be String") cf.cf_pos
 						end
 					in
 					begin match follow t with
 						| TFun((_,_,t1) :: (_,_,t2) :: args,_) when is_empty_or_pos_infos args ->
-							if a.a_read <> None then error "Multiple resolve-read methods are not supported" cf.cf_pos;
+							if a.a_read <> None then typing_error "Multiple resolve-read methods are not supported" cf.cf_pos;
 							check_fun t1 t2;
 							a.a_read <- Some cf;
 						| TFun((_,_,t1) :: (_,_,t2) :: (_,_,t3) :: args,_) when is_empty_or_pos_infos args ->
-							if a.a_write <> None then error "Multiple resolve-write methods are not supported" cf.cf_pos;
+							if a.a_write <> None then typing_error "Multiple resolve-write methods are not supported" cf.cf_pos;
 							check_fun t1 t2;
 							a.a_write <- Some cf;
 						| _ ->
-							error ("Field type of resolve must be " ^ (s_type (print_context()) targ) ^ " -> String -> T") cf.cf_pos
+							typing_error ("Field type of resolve must be " ^ (s_type (print_context()) targ) ^ " -> String -> T") cf.cf_pos
 					end;
 				| _ -> ());
 				match ml with
@@ -1146,8 +1146,8 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 			loop cf.cf_meta;
 			if cf.cf_name = "_new" && Meta.has Meta.MultiType a.a_meta then fctx.do_bind <- false;
 			if fd.f_expr = None then begin
-				if fctx.is_inline then error (cf.cf_name ^ ": Inline functions must have an expression") cf.cf_pos;
-				if fd.f_type = None then error (cf.cf_name ^ ": Functions without expressions must have an explicit return type") cf.cf_pos;
+				if fctx.is_inline then typing_error (cf.cf_name ^ ": Inline functions must have an expression") cf.cf_pos;
+				if fd.f_type = None then typing_error (cf.cf_name ^ ": Functions without expressions must have an explicit return type") cf.cf_pos;
 				if !allows_no_expr then begin
 					cf.cf_meta <- (Meta.NoExpr,[],null_pos) :: cf.cf_meta;
 					fctx.do_bind <- false;
@@ -1160,7 +1160,7 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 let create_method (ctx,cctx,fctx) c f fd p =
 	let params = TypeloadFunction.type_function_params ctx fd (fst f.cff_name) p in
 	if fctx.is_generic then begin
-		if params = [] then error (fst f.cff_name ^ ": Generic functions must have type parameters") p;
+		if params = [] then typing_error (fst f.cff_name ^ ": Generic functions must have type parameters") p;
 	end;
 	let fd = if fctx.is_macro && not ctx.in_macro && not fctx.is_static then
 		(* remove display of first argument which will contain the "this" expression *)
@@ -1192,7 +1192,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 			let to_dyn p t = match t with
 				| { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some ("ExprOf"); tparams = [TPType t] } -> Some t
 				| { tpackage = []; tname = ("ExprOf"); tsub = None; tparams = [TPType t] } -> Some t
-				| { tpackage = ["haxe"]; tname = ("PosInfos"); tsub = None; tparams = [] } -> error "haxe.PosInfos is not allowed on macro functions, use Context.currentPos() instead" p
+				| { tpackage = ["haxe"]; tname = ("PosInfos"); tsub = None; tparams = [] } -> typing_error "haxe.PosInfos is not allowed on macro functions, use Context.currentPos() instead" p
 				| _ -> tdyn
 			in
 			{
@@ -1204,18 +1204,18 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	end in
 	begin match (has_class_flag c CInterface),fctx.field_kind with
 		| true,FKConstructor ->
-			error "An interface cannot have a constructor" p;
+			typing_error "An interface cannot have a constructor" p;
 		| true,_ ->
-			if not fctx.is_static && fd.f_expr <> None then error (fst f.cff_name ^ ": An interface method cannot have a body") p;
-			if fctx.is_inline && (has_class_flag c CInterface) then error (fst f.cff_name ^ ": You can't declare inline methods in interfaces") p;
+			if not fctx.is_static && fd.f_expr <> None then typing_error (fst f.cff_name ^ ": An interface method cannot have a body") p;
+			if fctx.is_inline && (has_class_flag c CInterface) then typing_error (fst f.cff_name ^ ": You can't declare inline methods in interfaces") p;
 		| false,FKConstructor ->
-			if fctx.is_static then error "A constructor must not be static" p;
+			if fctx.is_static then typing_error "A constructor must not be static" p;
 			begin match fd.f_type with
 				| None -> ()
 				| Some (CTPath ({ tpackage = []; tname = "Void" } as tp),p) ->
 					if ctx.is_display_file && DisplayPosition.display_position#enclosed_in p then
 						ignore(load_instance ~allow_display:true ctx (tp,p) false);
-				| _ -> error "A class constructor can't have a return value" p;
+				| _ -> typing_error "A class constructor can't have a return value" p;
 			end
 		| false,_ ->
 			()
@@ -1223,9 +1223,9 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	let parent = (if not fctx.is_static then get_parent c (fst f.cff_name) else None) in
 	let dynamic = List.mem_assoc ADynamic f.cff_access || (match parent with Some { cf_kind = Method MethDynamic } -> true | _ -> false) in
 	if fctx.is_abstract && dynamic then display_error ctx "Abstract methods may not be dynamic" p;
-	if fctx.is_inline && dynamic then error (fst f.cff_name ^ ": 'inline' is not allowed on 'dynamic' functions") p;
+	if fctx.is_inline && dynamic then typing_error (fst f.cff_name ^ ": 'inline' is not allowed on 'dynamic' functions") p;
 	let is_override = Option.is_some fctx.override in
-	if (is_override && fctx.is_static) then error (fst f.cff_name ^ ": 'override' is not allowed on 'static' functions") p;
+	if (is_override && fctx.is_static) then typing_error (fst f.cff_name ^ ": 'override' is not allowed on 'static' functions") p;
 
 	ctx.type_params <- if fctx.is_static && not fctx.is_abstract_member then params else params @ ctx.type_params;
 	(* TODO is_lib: avoid forcing the return type to be typed *)
@@ -1313,13 +1313,13 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 	let name = fst f.cff_name in
 	(* TODO is_lib: lazify load_complex_type *)
 	let ret = (match t, eo with
-		| None, None -> error (name ^ ": Property requires type-hint or initialization") p;
+		| None, None -> typing_error (name ^ ": Property requires type-hint or initialization") p;
 		| None, _ -> mk_mono()
 		| Some t, _ -> lazy_display_type ctx (fun () -> load_type_hint ctx p (Some t))
 	) in
 	let t_get,t_set = match cctx.abstract with
 		| Some a when fctx.is_abstract_member ->
-			if Meta.has Meta.IsVar f.cff_meta then error (name ^ ": Abstract properties cannot be real variables") f.cff_pos;
+			if Meta.has Meta.IsVar f.cff_meta then typing_error (name ^ ": Abstract properties cannot be real variables") f.cff_pos;
 			let ta = apply_params a.a_params (List.map snd a.a_params) a.a_this in
 			tfun [ta] ret, tfun [ta;ret] ret
 		| _ -> tfun [] ret, TFun(["value",false,ret],ret)
@@ -1447,7 +1447,7 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 			display_error ctx (name ^ ": Custom property accessor is no longer supported, please use `set`") pset;
 			AccCall
 	) in
-	if (set = AccNever && get = AccNever)  then error (name ^ ": Unsupported property combination") p;
+	if (set = AccNever && get = AccNever)  then typing_error (name ^ ": Unsupported property combination") p;
 	cf.cf_kind <- Var { v_read = get; v_write = set };
 	if fctx.is_extern then add_class_field_flag cf CfExtern;
 	if Meta.has Meta.Enum cf.cf_meta then add_class_field_flag cf CfEnum;
@@ -1491,7 +1491,7 @@ let init_field (ctx,cctx,fctx) f =
 					try List.assoc AOverride f.cff_access
 					with Not_found -> p
 				in
-				error ("Invalid override on field '" ^ name ^ "': class has no super class") p
+				typing_error ("Invalid override on field '" ^ name ^ "': class has no super class") p
 			| _ -> ()
 			);
 		| None -> ()
@@ -1601,7 +1601,7 @@ let init_class ctx c p context_init herits fields =
 	in
 	let rec check_if_feature = function
 		| [] -> []
-		| (Meta.IfFeature,el,_) :: _ -> List.map (fun (e,p) -> match e with EConst (String(s,_)) -> s | _ -> error "String expected" p) el
+		| (Meta.IfFeature,el,_) :: _ -> List.map (fun (e,p) -> match e with EConst (String(s,_)) -> s | _ -> typing_error "String expected" p) el
 		| _ :: l -> check_if_feature l
 	in
 	let cl_if_feature = check_if_feature c.cl_meta in
@@ -1621,7 +1621,7 @@ let init_class ctx c p context_init herits fields =
 			end;
 			if fctx.is_field_debug then print_endline ("Created field: " ^ Printer.s_tclass_field "" cf);
 			if fctx.is_static && (has_class_flag c CInterface) && fctx.field_kind <> FKInit && not cctx.is_lib && not ((has_class_flag c CExtern)) then
-				error "You can only declare static fields in extern interfaces" p;
+				typing_error "You can only declare static fields in extern interfaces" p;
 			let set_feature s =
 				ctx.m.curmod.m_extra.m_if_feature <- (s,(c,cf,fctx.is_static)) :: ctx.m.curmod.m_extra.m_if_feature
 			in
@@ -1654,7 +1654,7 @@ let init_class ctx c p context_init herits fields =
 				()
 			| FKNormal ->
 				let dup = if fctx.is_static then PMap.exists cf.cf_name c.cl_fields || has_field cf.cf_name c.cl_super else PMap.exists cf.cf_name c.cl_statics in
-				if not cctx.is_native && not (has_class_flag c CExtern) && dup then error ("Same field name can't be used for both static and instance : " ^ cf.cf_name) p;
+				if not cctx.is_native && not (has_class_flag c CExtern) && dup then typing_error ("Same field name can't be used for both static and instance : " ^ cf.cf_name) p;
 				if fctx.override <> None then
 					add_class_field_flag cf CfOverride;
 				let is_var cf = match cf.cf_kind with | Var _ -> true | _ -> false in

+ 2 - 2
src/typing/typeloadFunction.ml

@@ -67,9 +67,9 @@ let type_function ctx (args : function_arguments) ret fmode e do_display p =
 				EBlock [],p
 			else
 				if fmode = FunMember && has_class_flag ctx.curclass CAbstract then
-					error "Function body or abstract modifier required" p
+					typing_error "Function body or abstract modifier required" p
 				else
-					error "Function body required" p
+					typing_error "Function body required" p
 		| Some e -> e
 	in
 	let is_position_debug = Meta.has (Meta.Custom ":debug.position") ctx.curfield.cf_meta in

+ 32 - 32
src/typing/typeloadModule.ml

@@ -198,7 +198,7 @@ let module_pass_1 ctx m tdecls loadp =
 		DeprecationCheck.check_is com name meta p;
 		let error prev_pos =
 			display_error ctx ("Name " ^ name ^ " is already defined in this module") p;
-			error (compl_msg "Previous declaration here") prev_pos;
+			typing_error (compl_msg "Previous declaration here") prev_pos;
 		in
 		List.iter (fun (t2,(_,p2)) ->
 			if snd (t_path t2) = name then error (t_infos t2).mt_name_pos
@@ -221,7 +221,7 @@ let module_pass_1 ctx m tdecls loadp =
 		in
 		let acc = (match fst decl with
 		| EImport _ | EUsing _ ->
-			if !has_declaration then error "import and using may not appear after a declaration" p;
+			if !has_declaration then typing_error "import and using may not appear after a declaration" p;
 			acc
 		| EStatic d ->
 			check_name (fst d.d_name) d.d_meta false (snd d.d_name);
@@ -235,7 +235,7 @@ let module_pass_1 ctx m tdecls loadp =
 			let path = make_path name priv d.d_meta (snd d.d_name) in
 			let c = mk_class m path p (pos d.d_name) in
 			(* we shouldn't load any other type until we propertly set cl_build *)
-			c.cl_build <- (fun() -> error (s_type_path c.cl_path ^ " is not ready to be accessed, separate your type declarations in several files") p);
+			c.cl_build <- (fun() -> typing_error (s_type_path c.cl_path ^ " is not ready to be accessed, separate your type declarations in several files") p);
 			c.cl_module <- m;
 			c.cl_private <- priv;
 			c.cl_doc <- d.d_doc;
@@ -259,7 +259,7 @@ let module_pass_1 ctx m tdecls loadp =
 			has_declaration := true;
 			let priv = List.mem EPrivate d.d_flags in
 			let path = make_path name priv d.d_meta p in
-			if Meta.has (Meta.Custom ":fakeEnum") d.d_meta then error "@:fakeEnum enums is no longer supported in Haxe 4, use extern enum abstract instead" p;
+			if Meta.has (Meta.Custom ":fakeEnum") d.d_meta then typing_error "@:fakeEnum enums is no longer supported in Haxe 4, use extern enum abstract instead" p;
 			let e = {
 				e_path = path;
 				e_module = m;
@@ -425,7 +425,7 @@ let load_enum_field ctx e et is_flat index c =
 			| TEnum (te,_) when te == e ->
 				()
 			| _ ->
-				error "Explicit enum type must be of the same enum type" pt);
+				typing_error "Explicit enum type must be of the same enum type" pt);
 			t
 	) in
 	let t = (match c.ec_args with
@@ -434,8 +434,8 @@ let load_enum_field ctx e et is_flat index c =
 			is_flat := false;
 			let pnames = ref PMap.empty in
 			TFun (List.map (fun (s,opt,(t,tp)) ->
-				(match t with CTPath({tpackage=[];tname="Void"}) -> error "Arguments of type Void are not allowed in enum constructors" tp | _ -> ());
-				if PMap.mem s (!pnames) then error ("Duplicate argument `" ^ s ^ "` in enum constructor " ^ fst c.ec_name) p;
+				(match t with CTPath({tpackage=[];tname="Void"}) -> typing_error "Arguments of type Void are not allowed in enum constructors" tp | _ -> ());
+				if PMap.mem s (!pnames) then typing_error ("Duplicate argument `" ^ s ^ "` in enum constructor " ^ fst c.ec_name) p;
 				pnames := PMap.add s () (!pnames);
 				s, opt, load_type_hint ~opt ctx p (Some (t,tp))
 			) l, rt)
@@ -496,24 +496,24 @@ let init_module_type ctx context_init (decl,p) =
 				(match List.rev path with
 				(* p spans `import |` (to the display position), so we take the pmax here *)
 				| [] -> DisplayException.raise_fields (DisplayToplevel.collect ctx TKType NoValue true) CRImport (DisplayTypes.make_subject None {p with pmin = p.pmax})
-				| (_,p) :: _ -> error "Module name must start with an uppercase letter" p))
+				| (_,p) :: _ -> typing_error "Module name must start with an uppercase letter" p))
 		| (tname,p2) :: rest ->
 			let p1 = (match pack with [] -> p2 | (_,p1) :: _ -> p1) in
 			let p_type = punion p1 p2 in
 			let md = ctx.g.do_load_module ctx (List.map fst pack,tname) p_type in
 			let types = md.m_types in
 			let no_private (t,_) = not (t_infos t).mt_private in
-			let error_private p = error "Importing private declarations from a module is not allowed" p in
+			let error_private p = typing_error "Importing private declarations from a module is not allowed" p in
 			let chk_private t p = if ctx.m.curmod != (t_infos t).mt_module && (t_infos t).mt_private then error_private p in
 			let has_name name t = snd (t_infos t).mt_path = name in
 			let get_type tname =
-				let t = (try List.find (has_name tname) types with Not_found -> error (StringError.string_error tname (List.map (fun mt -> snd (t_infos mt).mt_path) types) ("Module " ^ s_type_path md.m_path ^ " does not define type " ^ tname)) p_type) in
+				let t = (try List.find (has_name tname) types with Not_found -> typing_error (StringError.string_error tname (List.map (fun mt -> snd (t_infos mt).mt_path) types) ("Module " ^ s_type_path md.m_path ^ " does not define type " ^ tname)) p_type) in
 				chk_private t p_type;
 				t
 			in
 			let rebind t name p =
 				if not (name.[0] >= 'A' && name.[0] <= 'Z') then
-					error "Type aliases must start with an uppercase letter" p;
+					typing_error "Type aliases must start with an uppercase letter" p;
 				let _, _, f = ctx.g.do_build_instance ctx t p_type in
 				(* create a temp private typedef, does not register it in module *)
 				let mt = TTypeDecl {
@@ -608,7 +608,7 @@ let init_module_type ctx context_init (decl,p) =
 				| (tsub,p2) :: (fname,p3) :: rest ->
 					(match rest with
 					| [] -> ()
-					| (n,p) :: _ -> error ("Unexpected " ^ n) p);
+					| (n,p) :: _ -> typing_error ("Unexpected " ^ n) p);
 					let tsub = get_type tsub in
 					context_init#add (fun() ->
 						try
@@ -621,7 +621,7 @@ let init_module_type ctx context_init (decl,p) =
 				let t = (match rest with
 					| [] -> get_type tname
 					| [tsub,_] -> get_type tsub
-					| _ :: (n,p) :: _ -> error ("Unexpected " ^ n) p
+					| _ :: (n,p) :: _ -> typing_error ("Unexpected " ^ n) p
 				) in
 				context_init#add (fun() ->
 					match resolve_typedef t with
@@ -632,7 +632,7 @@ let init_module_type ctx context_init (decl,p) =
 					| TEnumDecl e ->
 						PMap.iter (fun _ c -> if not (has_meta Meta.NoImportGlobal c.ef_meta) then ctx.m.module_globals <- PMap.add c.ef_name (TEnumDecl e,c.ef_name,p) ctx.m.module_globals) e.e_constrs
 					| _ ->
-						error "No statics to import from this type" p
+						typing_error "No statics to import from this type" p
 				)
 			))
 	in
@@ -683,7 +683,7 @@ let init_module_type ctx context_init (decl,p) =
 					(match state with
 					| Built -> die "" __LOC__
 					| Building cl ->
-						if !build_count = !prev_build_count then error ("Loop in class building prevent compiler termination (" ^ String.concat "," (List.map (fun c -> s_type_path c.cl_path) cl) ^ ")") c.cl_pos;
+						if !build_count = !prev_build_count then typing_error ("Loop in class building prevent compiler termination (" ^ String.concat "," (List.map (fun c -> s_type_path c.cl_path) cl) ^ ")") c.cl_pos;
 						prev_build_count := !build_count;
 						rebuild();
 						Building (c :: cl)
@@ -729,7 +729,7 @@ let init_module_type ctx context_init (decl,p) =
 		(match h with
 		| None -> ()
 		| Some (h,hcl) ->
-			Hashtbl.iter (fun _ _ -> error "Field type patch not supported for enums" e.e_pos) h;
+			Hashtbl.iter (fun _ _ -> typing_error "Field type patch not supported for enums" e.e_pos) h;
 			e.e_meta <- e.e_meta @ hcl.tp_meta);
 		let constructs = ref d.d_data in
 		let get_constructs() =
@@ -753,10 +753,10 @@ let init_module_type ctx context_init (decl,p) =
 					let args, params, t = (match f.cff_kind with
 					| FVar (t,None) -> [], [], t
 					| FFun { f_params = pl; f_type = t; f_expr = (None|Some (EBlock [],_)); f_args = al } ->
-						let al = List.map (fun ((n,_),o,_,t,_) -> match t with None -> error "Missing function parameter type" f.cff_pos | Some t -> n,o,t) al in
+						let al = List.map (fun ((n,_),o,_,t,_) -> match t with None -> typing_error "Missing function parameter type" f.cff_pos | Some t -> n,o,t) al in
 						al, pl, t
 					| _ ->
-						error "Invalid enum constructor in @:build result" p
+						typing_error "Invalid enum constructor in @:build result" p
 					) in
 					{
 						ec_name = f.cff_name;
@@ -768,7 +768,7 @@ let init_module_type ctx context_init (decl,p) =
 						ec_type = t;
 					}
 				) fields
-			| _ -> error "Enum build macro must return a single variable with anonymous object fields" p
+			| _ -> typing_error "Enum build macro must return a single variable with anonymous object fields" p
 		);
 		let et = TEnum (e,List.map snd e.e_params) in
 		let names = ref [] in
@@ -776,7 +776,7 @@ let init_module_type ctx context_init (decl,p) =
 		let is_flat = ref true in
 		let fields = ref PMap.empty in
 		List.iter (fun c ->
-			if PMap.mem (fst c.ec_name) e.e_constrs then error ("Duplicate constructor " ^ fst c.ec_name) (pos c.ec_name);
+			if PMap.mem (fst c.ec_name) e.e_constrs then typing_error ("Duplicate constructor " ^ fst c.ec_name) (pos c.ec_name);
 			let f,cf = load_enum_field ctx e et is_flat index c in
 			e.e_constrs <- PMap.add f.ef_name f e.e_constrs;
 			fields := PMap.add cf.cf_name cf !fields;
@@ -812,14 +812,14 @@ let init_module_type ctx context_init (decl,p) =
 		| CTExtend _ -> tt
 		| CTPath { tpackage = ["haxe";"macro"]; tname = "MacroType" } ->
 			(* we need to follow MacroType immediately since it might define other module types that we will load afterwards *)
-			if t.t_type == follow tt then error "Recursive typedef is not allowed" p;
+			if t.t_type == follow tt then typing_error "Recursive typedef is not allowed" p;
 			tt
 		| _ ->
 			if (Meta.has Meta.Eager d.d_meta) then
 				follow tt
 			else begin
 				let rec check_rec tt =
-					if tt == t.t_type then error "Recursive typedef is not allowed" p;
+					if tt == t.t_type then typing_error "Recursive typedef is not allowed" p;
 					match tt with
 					| TMono r ->
 						(match r.tm_type with
@@ -828,7 +828,7 @@ let init_module_type ctx context_init (decl,p) =
 					| TLazy f ->
 						check_rec (lazy_type f);
 					| TType (td,tl) ->
-						if td == t then error "Recursive typedef is not allowed" p;
+						if td == t then typing_error "Recursive typedef is not allowed" p;
 						check_rec (apply_params td.t_params tl td.t_type)
 					| _ ->
 						()
@@ -867,15 +867,15 @@ let init_module_type ctx context_init (decl,p) =
 				if !is_type then begin
 					let r = exc_protect ctx (fun r ->
 						r := lazy_processing (fun() -> t);
-						(try (if from then Type.unify t a.a_this else Type.unify a.a_this t) with Unify_error _ -> error "You can only declare from/to with compatible types" pos);
+						(try (if from then Type.unify t a.a_this else Type.unify a.a_this t) with Unify_error _ -> typing_error "You can only declare from/to with compatible types" pos);
 						t
 					) "constraint" in
 					TLazy r
 				end else
-					error "Missing underlying type declaration or @:coreType declaration" p;
+					typing_error "Missing underlying type declaration or @:coreType declaration" p;
 			end else begin
 				if Meta.has Meta.Callable a.a_meta then
-					error "@:coreType abstracts cannot be @:callable" p;
+					typing_error "@:coreType abstracts cannot be @:callable" p;
 				t
 			end in
 			t
@@ -884,15 +884,15 @@ let init_module_type ctx context_init (decl,p) =
 			| AbFrom t -> a.a_from <- (load_type t true) :: a.a_from
 			| AbTo t -> a.a_to <- (load_type t false) :: a.a_to
 			| AbOver t ->
-				if a.a_impl = None then error "Abstracts with underlying type must have an implementation" a.a_pos;
-				if Meta.has Meta.CoreType a.a_meta then error "@:coreType abstracts cannot have an underlying type" p;
+				if a.a_impl = None then typing_error "Abstracts with underlying type must have an implementation" a.a_pos;
+				if Meta.has Meta.CoreType a.a_meta then typing_error "@:coreType abstracts cannot have an underlying type" p;
 				let at = load_complex_type ctx true t in
 				delay ctx PForce (fun () ->
 					let rec loop stack t =
 						match follow t with
 						| TAbstract(a,_) when not (Meta.has Meta.CoreType a.a_meta) ->
 							if List.memq a stack then
-								error "Abstract underlying type cannot be recursive" a.a_pos
+								typing_error "Abstract underlying type cannot be recursive" a.a_pos
 							else
 								loop (a :: stack) a.a_this
 						| _ -> ()
@@ -911,7 +911,7 @@ let init_module_type ctx context_init (decl,p) =
 			if Meta.has Meta.CoreType a.a_meta then
 				a.a_this <- TAbstract(a,List.map snd a.a_params)
 			else
-				error "Abstract is missing underlying type declaration" a.a_pos
+				typing_error "Abstract is missing underlying type declaration" a.a_pos
 		end;
 		if Meta.has Meta.InheritDoc a.a_meta then
 			delay ctx PConnectField (fun() -> InheritDoc.build_abstract_doc ctx a);
@@ -928,7 +928,7 @@ let module_pass_2 ctx m decls tdecls p =
 			c.cl_params <- type_type_params ctx c.cl_path (fun() -> c.cl_params) p d.d_params;
 			if Meta.has Meta.Generic c.cl_meta && c.cl_params <> [] then c.cl_kind <- KGeneric;
 			if Meta.has Meta.GenericBuild c.cl_meta then begin
-				if ctx.in_macro then error "@:genericBuild cannot be used in macros" c.cl_pos;
+				if ctx.in_macro then typing_error "@:genericBuild cannot be used in macros" c.cl_pos;
 				c.cl_kind <- KGenericBuild d.d_data;
 			end;
 			if c.cl_path = (["haxe";"macro"],"MacroType") then c.cl_kind <- KMacroType;
@@ -1040,7 +1040,7 @@ let handle_import_hx ctx m decls p =
 					| ParseSuccess(data,_,_) -> data
 					| ParseError(_,(msg,p),_) -> Parser.error msg p
 				in
-				List.iter (fun (d,p) -> match d with EImport _ | EUsing _ -> () | _ -> error "Only import and using is allowed in import.hx files" p) r;
+				List.iter (fun (d,p) -> match d with EImport _ | EUsing _ -> () | _ -> typing_error "Only import and using is allowed in import.hx files" p) r;
 				add_dependency m (make_import_module path r);
 				r
 			end else begin

+ 3 - 3
src/typing/typeloadParse.ml

@@ -40,7 +40,7 @@ let parse_file_from_lexbuf com file p lexbuf =
 	with
 		| Sedlexing.MalFormed ->
 			t();
-			error "Malformed file. Source files must be encoded with UTF-8." {pfile = file; pmin = 0; pmax = 0}
+			typing_error "Malformed file. Source files must be encoded with UTF-8." {pfile = file; pmin = 0; pmax = 0}
 		| e ->
 			t();
 			raise e
@@ -77,7 +77,7 @@ let parse_file com file p =
 		in
 		parse_file_from_string com file p s
 	else
-		let ch = try open_in_bin file with _ -> error ("Could not open " ^ file) p in
+		let ch = try open_in_bin file with _ -> typing_error ("Could not open " ^ file) p in
 		Std.finally (fun() -> close_in ch) (parse_file_from_lexbuf com file p) (Sedlexing.Utf8.from_channel ch)
 
 let parse_hook = ref parse_file
@@ -270,7 +270,7 @@ let handle_parser_result com p result =
 	let handle_parser_error msg p =
 		let msg = Parser.error_msg msg in
 		match com.display.dms_error_policy with
-			| EPShow -> error msg p
+			| EPShow -> typing_error msg p
 			| EPIgnore -> ()
 			| EPCollect -> add_diagnostics_message com msg p DKParserError Error
 	in

+ 48 - 48
src/typing/typer.ml

@@ -243,7 +243,7 @@ let rec unify_min_raise ctx (el:texpr list) : t =
 			| UnifyMinOk t ->
 				t
 			| UnifyMinError(l,index) ->
-				raise_error (Unify l) (List.nth el index).epos
+				raise_typing_error (Unify l) (List.nth el index).epos
 			end
 
 let unify_min ctx el =
@@ -277,20 +277,20 @@ let rec type_ident_raise ctx i p mode with_type =
 		(match mode, ctx.curclass.cl_kind with
 		| MSet _, KAbstractImpl _ ->
 			if not (assign_to_this_is_allowed ctx) then
-				error "Abstract 'this' value can only be modified inside an inline function" p;
+				typing_error "Abstract 'this' value can only be modified inside an inline function" p;
 			AKExpr (get_this ctx p)
 		| (MCall _, KAbstractImpl _) | (MGet, _)-> AKExpr(get_this ctx p)
 		| _ -> AKNo i)
 	| "super" ->
 		let t = (match ctx.curclass.cl_super with
-			| None -> error "Current class does not have a superclass" p
+			| None -> typing_error "Current class does not have a superclass" p
 			| Some (c,params) -> TInst(c,params)
 		) in
 		(match ctx.curfun with
 		| FunMember | FunConstructor -> ()
-		| FunMemberAbstract -> error "Cannot access super inside an abstract function" p
-		| FunStatic -> error "Cannot access super inside a static function" p;
-		| FunMemberClassLocal | FunMemberAbstractLocal -> error "Cannot access super inside a local function" p);
+		| FunMemberAbstract -> typing_error "Cannot access super inside an abstract function" p
+		| FunStatic -> typing_error "Cannot access super inside a static function" p;
+		| FunMemberClassLocal | FunMemberAbstractLocal -> typing_error "Cannot access super inside a local function" p);
 		AKExpr (mk (TConst TSuper) t p)
 	| "null" ->
 		if mode = MGet then
@@ -307,8 +307,8 @@ let rec type_ident_raise ctx i p mode with_type =
 			(match e with
 			| Some ({ eexpr = TFunction f } as e) when ctx.com.display.dms_inline ->
 				begin match mode with
-					| MSet _ -> error "Cannot set inline closure" p
-					| MGet -> error "Cannot create closure on inline closure" p
+					| MSet _ -> typing_error "Cannot set inline closure" p
+					| MGet -> typing_error "Cannot create closure on inline closure" p
 					| MCall _ ->
 						(* create a fake class with a fake field to emulate inlining *)
 						let c = mk_class ctx.m.curmod (["local"],v.v_name) e.epos null_pos in
@@ -333,7 +333,7 @@ let rec type_ident_raise ctx i p mode with_type =
 		let is_impl = has_class_field_flag f CfImpl in
 		let is_enum = has_class_field_flag f CfEnum in
 		if is_impl && not (has_class_field_flag ctx.curfield CfImpl) && not is_enum then
-			error (Printf.sprintf "Cannot access non-static field %s from static method" f.cf_name) p;
+			typing_error (Printf.sprintf "Cannot access non-static field %s from static method" f.cf_name) p;
 		let e,fa = match ctx.curclass.cl_kind with
 			| KAbstractImpl a when is_impl && not is_enum ->
 				let tl = List.map snd a.a_params in
@@ -435,7 +435,7 @@ and type_ident ctx i p mode with_type =
 					let t = mk_mono() in
 					AKExpr ((mk (TIdent i)) t p)
 			end else begin
-				if ctx.curfun = FunStatic && PMap.mem i ctx.curclass.cl_fields then error ("Cannot access " ^ i ^ " in static function") p;
+				if ctx.curfun = FunStatic && PMap.mem i ctx.curclass.cl_fields then typing_error ("Cannot access " ^ i ^ " in static function") p;
 				if !resolved_to_type_parameter then begin
 					display_error ctx ("Only @:const type parameters on @:generic classes can be used as value") p;
 					AKExpr (mk (TConst TNull) t_dynamic p)
@@ -550,8 +550,8 @@ and type_access ctx e p mode with_type =
 		begin match e1.eexpr with
 			| TTypeExpr (TClassDecl c) ->
 				begin match mode with
-				| MSet _ -> error "Cannot set constructor" p;
-				| MCall _ -> error ("Cannot call constructor like this, use 'new " ^ (s_type_path c.cl_path) ^ "()' instead") p;
+				| MSet _ -> typing_error "Cannot set constructor" p;
+				| MCall _ -> typing_error ("Cannot call constructor like this, use 'new " ^ (s_type_path c.cl_path) ^ "()' instead") p;
 				| MGet -> ()
 				end;
 				let monos = Monomorph.spawn_constrained_monos (fun t -> t) (match c.cl_kind with KAbstractImpl a -> a.a_params | _ -> c.cl_params) in
@@ -580,7 +580,7 @@ and type_access ctx e p mode with_type =
 					tf_type = t;
 					tf_expr = mk (TReturn (Some ec)) t p;
 				}) (TFun ((List.map (fun v -> v.v_name,false,v.v_type) vl),t)) p)
-			| _ -> error "Binding new is only allowed on class types" p
+			| _ -> typing_error "Binding new is only allowed on class types" p
 		end;
 	| EField _ ->
 		handle_efield ctx e p mode with_type
@@ -625,7 +625,7 @@ and type_vars ctx vl p =
 		List.iter
 			(fun (v,_) ->
 				if ExtType.is_void (follow v.v_type) then
-					error "Variables of type Void are not allowed" v.v_pos
+					typing_error "Variables of type Void are not allowed" v.v_pos
 			)
 			vl
 	);
@@ -700,7 +700,7 @@ and format_string ctx s p =
 			if i = len then
 				match groups with
 				| [] -> die "" __LOC__
-				| g :: _ -> error ("Unclosed " ^ gname) { p with pmin = !pmin + g + 1; pmax = !pmin + g + 2 }
+				| g :: _ -> typing_error ("Unclosed " ^ gname) { p with pmin = !pmin + g + 1; pmax = !pmin + g + 2 }
 			else
 				let c = String.unsafe_get s i in
 				if c = gopen then
@@ -719,8 +719,8 @@ and format_string ctx s p =
 			let e =
 				let ep = { p with pmin = !pmin + pos + 2; pmax = !pmin + send + 1 } in
 				let error msg pos =
-					if Lexer.string_is_whitespace scode then error "Expression cannot be empty" ep
-					else error msg pos
+					if Lexer.string_is_whitespace scode then typing_error "Expression cannot be empty" ep
+					else typing_error msg pos
 				in
 				match ParserEntry.parse_expr_string ctx.com.defines scode ep error true with
 					| ParseSuccess(data,_,_) -> data
@@ -792,7 +792,7 @@ and type_object_decl ctx fl with_type p =
 		let extra_fields = ref [] in
 		let fl = List.map (fun ((n,pn,qs),e) ->
 			let is_valid = Lexer.is_valid_identifier n in
-			if PMap.mem n !fields then error ("Duplicate field in object declaration : " ^ n) p;
+			if PMap.mem n !fields then typing_error ("Duplicate field in object declaration : " ^ n) p;
 			let is_final = ref false in
 			let e = try
 				let t = match !dynamic_parameter with
@@ -813,7 +813,7 @@ and type_object_decl ctx fl with_type p =
 				type_expr ctx e WithType.value
 			in
 			if is_valid then begin
-				if starts_with n '$' then error "Field names starting with a dollar are not allowed" p;
+				if starts_with n '$' then typing_error "Field names starting with a dollar are not allowed" p;
 				let cf = mk_field n e.etype (punion pn e.epos) pn in
 				if !is_final then add_class_field_flag cf CfFinal;
 				fields := PMap.add n cf !fields;
@@ -835,13 +835,13 @@ and type_object_decl ctx fl with_type p =
 	let type_plain_fields () =
 		let rec loop (l,acc) ((f,pf,qs),e) =
 			let is_valid = Lexer.is_valid_identifier f in
-			if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
+			if PMap.mem f acc then typing_error ("Duplicate field in object declaration : " ^ f) p;
 			let e = type_expr ctx e (WithType.named_structure_field f) in
-			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
+			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> typing_error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
 			let cf = mk_field f e.etype (punion pf e.epos) pf in
 			if ctx.in_display && DisplayPosition.display_position#enclosed_in pf then DisplayEmitter.display_field ctx Unknown CFSMember cf pf;
 			(((f,pf,qs),e) :: l, if is_valid then begin
-				if starts_with f '$' then error "Field names starting with a dollar are not allowed" p;
+				if starts_with f '$' then typing_error "Field names starting with a dollar are not allowed" p;
 				PMap.add f cf acc
 			end else acc)
 		in
@@ -930,7 +930,7 @@ and type_new ctx path el with_type force_inline p =
 			check_constructor_access ctx c fcc.fc_field p;
 			fcc
 		with Error (e,p) ->
-			error (error_msg e) p;
+			typing_error (error_msg e) p;
 	in
 	let t = if (fst path).tparams <> [] then begin
 		try
@@ -973,7 +973,7 @@ and type_new ctx path el with_type force_inline p =
 				end
 			end
 		| mt ->
-			error ((s_type_path (t_infos mt).mt_path) ^ " cannot be constructed") p
+			typing_error ((s_type_path (t_infos mt).mt_path) ^ " cannot be constructed") p
 		end
 	| Error _ as exc when ctx.com.display.dms_display ->
 		List.iter (fun e -> ignore(type_expr ctx e WithType.value)) el;
@@ -987,17 +987,17 @@ and type_new ctx path el with_type force_inline p =
 		let cf = fa.fa_field in
 		no_abstract_constructor c p;
 		begin match cf.cf_kind with
-			| Var { v_read = AccRequire (r,msg) } -> (match msg with Some msg -> error msg p | None -> error_require r p)
+			| Var { v_read = AccRequire (r,msg) } -> (match msg with Some msg -> typing_error msg p | None -> error_require r p)
 			| _ -> ()
 		end;
 		unify_constructor_call c fa
 	in
 	try begin match Abstract.follow_with_forward_ctor t with
 	| TInst ({cl_kind = KTypeParameter tl} as c,params) ->
-		if not (TypeloadCheck.is_generic_parameter ctx c) then error "Only generic type parameters can be constructed" p;
+		if not (TypeloadCheck.is_generic_parameter ctx c) then typing_error "Only generic type parameters can be constructed" p;
  		begin match get_constructible_constraint ctx tl p with
 		| None ->
-			raise_error (No_constructor (TClassDecl c)) p
+			raise_typing_error (No_constructor (TClassDecl c)) p
 		| Some(tl,tr) ->
 			let el,_ = unify_call_args ctx el tl tr p false false false in
 			mk (TNew (c,params,el)) t p
@@ -1010,7 +1010,7 @@ and type_new ctx path el with_type force_inline p =
 		let el = fcc.fc_args in
 		mk (TNew (c,params,el)) t p
 	| _ ->
-		error (s_type (print_context()) t ^ " cannot be constructed") p
+		typing_error (s_type (print_context()) t ^ " cannot be constructed") p
 	end with Error(No_constructor _ as err,p) when ctx.com.display.dms_kind <> DMNone ->
 		display_error ctx (error_msg err) p;
 		Diagnostics.secure_generated_code ctx (mk (TConst TNull) t p)
@@ -1045,7 +1045,7 @@ and type_try ctx e1 catches with_type p =
 	in
 	let check_catch_type_params params p =
 		List.iter (fun pt ->
-			if Abstract.follow_with_abstracts pt != t_dynamic then error "Catch class parameter must be Dynamic" p;
+			if Abstract.follow_with_abstracts pt != t_dynamic then typing_error "Catch class parameter must be Dynamic" p;
 		) params
 	in
 	let catches,el = List.fold_left (fun (acc1,acc2) ((v,pv),t,e_ast,pc) ->
@@ -1053,7 +1053,7 @@ and type_try ctx e1 catches with_type p =
 		let t = Typeload.load_complex_type ctx true th in
 		let rec loop t = match follow t with
 			| TInst ({ cl_kind = KTypeParameter _} as c,_) when not (TypeloadCheck.is_generic_parameter ctx c) ->
-				error "Cannot catch non-generic type parameter" p
+				typing_error "Cannot catch non-generic type parameter" p
 			| TInst (_,params) | TEnum (_,params) ->
 				check_catch_type_params params (snd th);
 				t
@@ -1063,7 +1063,7 @@ and type_try ctx e1 catches with_type p =
 			| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				loop (Abstract.get_underlying_type a tl)
 			| TDynamic _ -> t
-			| _ -> error "Catch type must be a class, an enum or Dynamic" (pos e_ast)
+			| _ -> typing_error "Catch type must be a class, an enum or Dynamic" (pos e_ast)
 		in
 		let t2 = loop t in
 		check_unreachable acc1 t2 (pos e_ast);
@@ -1111,7 +1111,7 @@ and type_map_declaration ctx e1 el with_type p =
 		try
 			let p = Hashtbl.find keys e_key.eexpr in
 			display_error ctx "Duplicate key" e_key.epos;
-			error (compl_msg "Previously defined here") p
+			typing_error (compl_msg "Previously defined here") p
 		with Not_found ->
 			begin match e_key.eexpr with
 			| TConst _ -> Hashtbl.add keys e_key.eexpr e_key.epos;
@@ -1123,8 +1123,8 @@ and type_map_declaration ctx e1 el with_type p =
 		| EBinop(OpArrow,e1,e2) -> e1,e2
 		| EDisplay _ ->
 			ignore(type_expr ctx e (WithType.with_type tkey));
-			error "Expected a => b" (pos e)
-		| _ -> error "Expected a => b" (pos e)
+			typing_error "Expected a => b" (pos e)
+		| _ -> typing_error "Expected a => b" (pos e)
 	) el in
 	let el_k,el_v,tkey,tval = if has_type then begin
 		let el_k,el_v = List.fold_left (fun (el_k,el_v) (e1,e2) ->
@@ -1168,7 +1168,7 @@ and type_local_function ctx kind f with_type p =
 	let params = TypeloadFunction.type_function_params ctx f (match name with None -> "localfun" | Some (n,_) -> n) p in
 	if params <> [] then begin
 		if name = None then display_error ctx "Type parameters not supported in unnamed local functions" p;
-		if with_type <> WithType.NoValue then error "Type parameters are not supported for rvalue functions" p
+		if with_type <> WithType.NoValue then typing_error "Type parameters are not supported for rvalue functions" p
 	end;
 	let v,pname = (match name with
 		| None -> None,p
@@ -1398,7 +1398,7 @@ and type_return ?(implicit=false) ctx e with_type p =
 				match follow e.etype with
 				| TAbstract({a_path=[],"Void"},_) ->
 					begin match (Texpr.skip e).eexpr with
-					| TConst TNull -> error "Cannot return `null` from Void-function" p
+					| TConst TNull -> typing_error "Cannot return `null` from Void-function" p
 					| _ -> ()
 					end;
 					(* if we get a Void expression (e.g. from inlining) we don't want to return it (issue #4323) *)
@@ -1421,14 +1421,14 @@ and type_cast ctx e t p =
 	let check_param pt = match follow pt with
 		| TMono _ -> () (* This probably means that Dynamic wasn't bound (issue #4675). *)
 		| t when t == t_dynamic -> ()
-		| _ -> error "Cast type parameters must be Dynamic" tpos
+		| _ -> typing_error "Cast type parameters must be Dynamic" tpos
 	in
 	let rec loop t = match follow t with
 		| TInst (_,params) | TEnum (_,params) ->
 			List.iter check_param params;
 			(match follow t with
 			| TInst (c,_) ->
-				(match c.cl_kind with KTypeParameter _ -> error "Can't cast to a type parameter" tpos | _ -> ());
+				(match c.cl_kind with KTypeParameter _ -> typing_error "Can't cast to a type parameter" tpos | _ -> ());
 				TClassDecl c
 			| TEnum (e,_) -> TEnumDecl e
 			| _ -> die "" __LOC__);
@@ -1438,7 +1438,7 @@ and type_cast ctx e t p =
 		| TAbstract (a,params) ->
 			loop (Abstract.get_underlying_type a params)
 		| _ ->
-			error "Cast type must be a class or an enum" tpos
+			typing_error "Cast type must be a class or an enum" tpos
 	in
 	let texpr = loop t in
 	mk (TCast (type_expr ctx e WithType.value,Some texpr)) t p
@@ -1476,10 +1476,10 @@ and type_meta ?(mode=MGet) ctx m e1 with_type p =
 				| TAbstract({a_impl = Some c},_) when PMap.mem "toString" c.cl_statics -> call_to_string ctx e
 				| _ -> e)
 		| (Meta.Markup,_,_) ->
-			error "Markup literals must be processed by a macro" p
+			typing_error "Markup literals must be processed by a macro" p
 		| (Meta.This,_,_) ->
 			let e = match ctx.this_stack with
-				| [] -> error "Cannot type @:this this here" p
+				| [] -> typing_error "Cannot type @:this this here" p
 				| e :: _ -> e
 			in
 			let rec loop e = match e.eexpr with
@@ -1629,9 +1629,9 @@ and type_call ?(mode=MGet) ctx e el (with_type:WithType.t) inline p =
 	| (EDisplay((EConst (Ident "super"),_ as e1),dk),_),_ ->
 		TyperDisplay.handle_display ctx (ECall(e1,el),p) dk mode with_type
 	| (EConst (Ident "super"),sp) , el ->
-		if ctx.curfun <> FunConstructor then error "Cannot call super constructor outside class constructor" p;
+		if ctx.curfun <> FunConstructor then typing_error "Cannot call super constructor outside class constructor" p;
 		let el, t = (match ctx.curclass.cl_super with
-		| None -> error "Current class does not have a super" p
+		| None -> typing_error "Current class does not have a super" p
 		| Some (c,params) ->
 			let fa = FieldAccess.get_constructor_access c params p in
 			let cf = fa.fa_field in
@@ -1650,12 +1650,12 @@ and type_call ?(mode=MGet) ctx e el (with_type:WithType.t) inline p =
 and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
 	match e with
 	| EField ((EConst (String(s,_)),ps),"code") ->
-		if UTF8.length s <> 1 then error "String must be a single UTF8 char" ps;
+		if UTF8.length s <> 1 then typing_error "String must be a single UTF8 char" ps;
 		mk (TConst (TInt (Int32.of_int (UCharExt.code (UTF8.get s 0))))) ctx.t.tint p
 	| EField(_,n) when starts_with n '$' ->
-		error "Field names starting with $ are not allowed" p
+		typing_error "Field names starting with $ are not allowed" p
 	| EConst (Ident s) ->
-		if s = "super" && with_type <> WithType.NoValue && not ctx.in_display then error "Cannot use super as value" p;
+		if s = "super" && with_type <> WithType.NoValue && not ctx.in_display then typing_error "Cannot use super as value" p;
 		let e = maybe_type_against_enum ctx (fun () -> type_ident ctx s p mode with_type) with_type false p in
 		acc_get ctx e p
 	| EField _
@@ -1909,9 +1909,9 @@ let rec create com =
 		Error (Module_not_found ([],"StdTypes"),_) ->
 			try
 				let std_path = Sys.getenv "HAXE_STD_PATH" in
-				error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
+				typing_error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
 			with Not_found ->
-				error "Standard library not found. You may need to set your `HAXE_STD_PATH` environment variable" null_pos
+				typing_error "Standard library not found. You may need to set your `HAXE_STD_PATH` environment variable" null_pos
 	);
 	(* We always want core types to be available so we add them as default imports (issue #1904 and #3131). *)
 	ctx.m.module_types <- List.map (fun t -> t,null_pos) ctx.g.std.m_types;

+ 7 - 7
src/typing/typerBase.ml

@@ -33,12 +33,12 @@ let type_access_ref : (typer -> expr_def -> pos -> access_mode -> WithType.t ->
 
 let is_lower_ident s p =
 	try Ast.is_lower_ident s
-	with Invalid_argument msg -> error msg p
+	with Invalid_argument msg -> typing_error msg p
 
 let get_this ctx p =
 	match ctx.curfun with
 	| FunStatic ->
-		error "Cannot access this from a static function" p
+		typing_error "Cannot access this from a static function" p
 	| FunMemberClassLocal | FunMemberAbstractLocal ->
 		let v = match ctx.vthis with
 			| None ->
@@ -55,7 +55,7 @@ let get_this ctx p =
 		in
 		mk (TLocal v) ctx.tthis p
 	| FunMemberAbstract ->
-		let v = (try PMap.find "this" ctx.locals with Not_found -> error "Cannot reference this abstract here" p) in
+		let v = (try PMap.find "this" ctx.locals with Not_found -> typing_error "Cannot reference this abstract here" p) in
 		mk (TLocal v) v.v_type p
 	| FunConstructor | FunMember ->
 		mk (TConst TThis) ctx.tthis p
@@ -79,7 +79,7 @@ let rec type_module_type ctx t tparams p =
 			module_type_of_type t
 		with Exit ->
 			if follow t == t_dynamic then Typeload.load_type_def ctx p (mk_type_path ([],"Dynamic"))
-			else error "Invalid module type" p
+			else typing_error "Invalid module type" p
 		in
 		type_module_type ctx mt None p
 	| TClassDecl c ->
@@ -99,11 +99,11 @@ let rec type_module_type ctx t tparams p =
 		| TAbstract (a,params) ->
 			type_module_type ctx (TAbstractDecl a) (Some params) p
 		| _ ->
-			error (s_type_path s.t_path ^ " is not a value") p)
+			typing_error (s_type_path s.t_path ^ " is not a value") p)
 	| TAbstractDecl { a_impl = Some c } ->
 		type_module_type ctx (TClassDecl c) tparams p
 	| TAbstractDecl a ->
-		if not (Meta.has Meta.RuntimeValue a.a_meta) then error (s_type_path a.a_path ^ " is not a value") p;
+		if not (Meta.has Meta.RuntimeValue a.a_meta) then typing_error (s_type_path a.a_path ^ " is not a value") p;
 		let t_tmp = abstract_module_type a [] in
 		mk (TTypeExpr (TAbstractDecl a)) (TType (t_tmp,[])) p
 
@@ -151,7 +151,7 @@ let s_access_kind acc =
 let get_constructible_constraint ctx tl p =
 	let extract_function t = match follow t with
 		| TFun(tl,tr) -> tl,tr
-		| _ -> error "Constructible type parameter should be function" p
+		| _ -> typing_error "Constructible type parameter should be function" p
 	in
 	let rec loop tl = match tl with
 		| [] -> None

+ 7 - 7
src/typing/typerDisplay.ml

@@ -179,7 +179,7 @@ let display_dollar_type ctx p make_type =
 	| DMDefinition | DMTypeDefinition ->
 		raise_positions []
 	| _ ->
-		error "Unsupported method" p
+		typing_error "Unsupported method" p
 	end
 
 let rec handle_signature_display ctx e_ast with_type =
@@ -189,7 +189,7 @@ let rec handle_signature_display ctx e_ast with_type =
 		let rec follow_with_callable (t,doc,values) = match follow t with
 			| TAbstract(a,tl) when Meta.has Meta.Callable a.a_meta -> follow_with_callable (Abstract.get_underlying_type a tl,doc,values)
 			| TFun(args,ret) -> ((args,ret),doc,values)
-			| _ -> error ("Not a callable type: " ^ (s_type (print_context()) t)) p
+			| _ -> typing_error ("Not a callable type: " ^ (s_type (print_context()) t)) p
 		in
 		let tl = List.map follow_with_callable tl in
 		let rec loop i acc el = match el with
@@ -227,7 +227,7 @@ let rec handle_signature_display ctx e_ast with_type =
 	let find_constructor_types t = match follow t with
 		| TInst ({cl_kind = KTypeParameter tl} as c,_) ->
 			let rec loop tl = match tl with
-				| [] -> raise_error (No_constructor (TClassDecl c)) p
+				| [] -> raise_typing_error (No_constructor (TClassDecl c)) p
 				| t :: tl -> match follow t with
 					| TAbstract({a_path = ["haxe"],"Constructible"},[t]) -> t
 					| _ -> loop tl
@@ -312,11 +312,11 @@ let rec handle_signature_display ctx e_ast with_type =
 			| _ ->
 				raise_signatures [] 0 0 SKArrayAccess
 			end
-		| _ -> error "Call expected" p
+		| _ -> typing_error "Call expected" p
 
 and display_expr ctx e_ast e dk mode with_type p =
 	let get_super_constructor () = match ctx.curclass.cl_super with
-		| None -> error "Current class does not have a super" p
+		| None -> typing_error "Current class does not have a super" p
 		| Some (c,params) ->
 			let fa = get_constructor_access c params p in
 			fa.fa_field,c
@@ -516,7 +516,7 @@ let handle_display ctx e_ast dk mode with_type =
 		| DMDefinition | DMTypeDefinition ->
 			raise_positions []
 		| _ ->
-			error "Unsupported method" p
+			typing_error "Unsupported method" p
 		end
 	| (EConst (Ident "_"),p),WithType.WithType(t,_) ->
 		mk (TConst TNull) t p (* This is "probably" a bind skip, let's just use the expected type *)
@@ -669,7 +669,7 @@ let handle_structure_display ctx e fields origin =
 		let pinsert = DisplayPosition.display_position#with_pos (pos e) in
 		raise_fields fields CRStructureField (make_subject None pinsert)
 	| _ ->
-		error "Expected object expression" p
+		typing_error "Expected object expression" p
 
 let handle_edisplay ctx e dk mode with_type =
 	let handle_display ctx e dk with_type =