|
@@ -97,7 +97,7 @@ let maybe_type_against_enum ctx f with_type iscall p =
|
|
|
let e = try
|
|
|
f()
|
|
|
with
|
|
|
- | Error (Unknown_ident n,_,_) ->
|
|
|
+ | Error { err_message = Unknown_ident n; err_sub = sub } ->
|
|
|
restore();
|
|
|
raise_or_display_message ctx (StringError.string_error n fields ("Identifier '" ^ n ^ "' is not part of " ^ s_type_path path)) p;
|
|
|
AKExpr (mk (TConst TNull) (mk_mono()) p)
|
|
@@ -243,13 +243,13 @@ let rec unify_min_raise ctx (el:texpr list) : t =
|
|
|
| UnifyMinOk t ->
|
|
|
t
|
|
|
| UnifyMinError(l,index) ->
|
|
|
- raise_typing_error (Unify l) (List.nth el index).epos
|
|
|
+ raise_typing_error_ext (make_error (Unify l) (List.nth el index).epos)
|
|
|
end
|
|
|
|
|
|
let unify_min ctx el =
|
|
|
try unify_min_raise ctx el
|
|
|
- with Error (Unify l,p,depth) ->
|
|
|
- if not ctx.untyped then located_display_error ~depth ctx.com (error_msg p (Unify l));
|
|
|
+ with Error ({ err_message = Unify l } as err) ->
|
|
|
+ if not ctx.untyped then display_error_ext ctx.com err;
|
|
|
(List.hd el).etype
|
|
|
|
|
|
let unify_min_for_type_source ctx el src =
|
|
@@ -282,7 +282,7 @@ let rec type_ident_raise ctx i p mode with_type =
|
|
|
begin match ctx.curclass.cl_kind with
|
|
|
| KAbstractImpl _ ->
|
|
|
if not (assign_to_this_is_allowed ctx) then
|
|
|
- typing_error "Abstract 'this' value can only be modified inside an inline function" p;
|
|
|
+ raise_typing_error "Abstract 'this' value can only be modified inside an inline function" p;
|
|
|
acc
|
|
|
| _ ->
|
|
|
AKNo(acc,p)
|
|
@@ -299,7 +299,7 @@ let rec type_ident_raise ctx i p mode with_type =
|
|
|
end;
|
|
|
| "abstract" ->
|
|
|
begin match mode, ctx.curclass.cl_kind with
|
|
|
- | MSet _, KAbstractImpl ab -> typing_error "Property 'abstract' is read-only" p;
|
|
|
+ | MSet _, KAbstractImpl ab -> raise_typing_error "Property 'abstract' is read-only" p;
|
|
|
| (MGet, KAbstractImpl ab)
|
|
|
| (MCall _, KAbstractImpl ab) ->
|
|
|
let tl = extract_param_types ab.a_params in
|
|
@@ -307,18 +307,18 @@ let rec type_ident_raise ctx i p mode with_type =
|
|
|
let e = {e with etype = TAbstract (ab,tl)} in
|
|
|
AKExpr e
|
|
|
| _ ->
|
|
|
- typing_error "Property 'abstract' is reserved and only available in abstracts" p
|
|
|
+ raise_typing_error "Property 'abstract' is reserved and only available in abstracts" p
|
|
|
end
|
|
|
| "super" ->
|
|
|
let t = (match ctx.curclass.cl_super with
|
|
|
- | None -> typing_error "Current class does not have a superclass" p
|
|
|
+ | None -> raise_typing_error "Current class does not have a superclass" p
|
|
|
| Some (c,params) -> TInst(c,params)
|
|
|
) in
|
|
|
(match ctx.curfun with
|
|
|
| FunMember | FunConstructor -> ()
|
|
|
- | 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);
|
|
|
+ | FunMemberAbstract -> raise_typing_error "Cannot access super inside an abstract function" p
|
|
|
+ | FunStatic -> raise_typing_error "Cannot access super inside a static function" p;
|
|
|
+ | FunMemberClassLocal | FunMemberAbstractLocal -> raise_typing_error "Cannot access super inside a local function" p);
|
|
|
AKExpr (mk (TConst TSuper) t p)
|
|
|
| "null" ->
|
|
|
let acc =
|
|
@@ -356,8 +356,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 _ -> typing_error "Cannot set inline closure" p
|
|
|
- | MGet -> typing_error "Cannot create closure on inline closure" p
|
|
|
+ | MSet _ -> raise_typing_error "Cannot set inline closure" p
|
|
|
+ | MGet -> raise_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
|
|
@@ -382,7 +382,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
|
|
|
- typing_error (Printf.sprintf "Cannot access non-static field %s from static method" f.cf_name) p;
|
|
|
+ raise_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 = extract_param_types a.a_params in
|
|
@@ -465,7 +465,7 @@ and type_ident ctx i p mode with_type =
|
|
|
with Not_found -> try
|
|
|
(* lookup type *)
|
|
|
if is_lower_ident i p then raise Not_found;
|
|
|
- let e = (try type_type ctx ([],i) p with Error (Module_not_found ([],name),_,_) when name = i -> raise Not_found) in
|
|
|
+ let e = (try type_type ctx ([],i) p with Error { err_message = Module_not_found ([],name) } when name = i -> raise Not_found) in
|
|
|
AKExpr e
|
|
|
with Not_found ->
|
|
|
let resolved_to_type_parameter = ref false in
|
|
@@ -486,14 +486,14 @@ 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 typing_error ("Cannot access " ^ i ^ " in static function") p;
|
|
|
+ if ctx.curfun = FunStatic && PMap.mem i ctx.curclass.cl_fields then raise_typing_error ("Cannot access " ^ i ^ " in static function") p;
|
|
|
if !resolved_to_type_parameter then begin
|
|
|
display_error ctx.com ("Only @:const type parameters on @:generic classes can be used as value") p;
|
|
|
AKExpr (mk (TConst TNull) t_dynamic p)
|
|
|
end else begin
|
|
|
let err = Unknown_ident i in
|
|
|
if ctx.in_display then begin
|
|
|
- raise (Error (err,p,0))
|
|
|
+ raise_error_msg err p
|
|
|
end;
|
|
|
if Diagnostics.error_in_diagnostics_run ctx.com p then begin
|
|
|
DisplayToplevel.handle_unresolved_identifier ctx i p false;
|
|
@@ -502,9 +502,9 @@ and type_ident ctx i p mode with_type =
|
|
|
AKExpr (mk (TIdent i) t p)
|
|
|
end else match ctx.com.display.dms_kind with
|
|
|
| DMNone ->
|
|
|
- raise (Error(err,p,0))
|
|
|
+ raise_error_msg err p
|
|
|
| _ ->
|
|
|
- located_display_error ctx.com (error_msg p err);
|
|
|
+ display_error ctx.com (error_msg err) p;
|
|
|
let t = mk_mono() in
|
|
|
(* Add a fake local for #8751. *)
|
|
|
if !ServerConfig.legacy_completion then
|
|
@@ -533,7 +533,7 @@ and handle_efield ctx e p0 mode with_type =
|
|
|
try
|
|
|
(* TODO: we don't really want to do full type_ident again, just the second part of it *)
|
|
|
field_chain ctx pnext (type_ident ctx name p MGet WithType.value)
|
|
|
- with Error (Unknown_ident _,p2,_) as e when p = p2 ->
|
|
|
+ with Error ({ err_message = Unknown_ident _; err_pos = p2 } as e) when p = p2 ->
|
|
|
try
|
|
|
(* try raising a more sensible error if there was an uppercase-first (module name) part *)
|
|
|
begin
|
|
@@ -557,9 +557,9 @@ and handle_efield ctx e p0 mode with_type =
|
|
|
let mpath = (pack,name) in
|
|
|
if ctx.com.module_lut#mem mpath then
|
|
|
let tname = Option.default name sub in
|
|
|
- raise (Error (Type_not_found (mpath,tname,Not_defined),p,0))
|
|
|
+ raise_error_msg (Type_not_found (mpath,tname,Not_defined)) p
|
|
|
else
|
|
|
- raise (Error (Module_not_found mpath,p,0))
|
|
|
+ raise_error_msg (Module_not_found mpath) p
|
|
|
end
|
|
|
with Not_found ->
|
|
|
(* if there was no module name part, last guess is that we're trying to get package completion *)
|
|
@@ -570,7 +570,7 @@ and handle_efield ctx e p0 mode with_type =
|
|
|
else
|
|
|
DisplayToplevel.collect_and_raise ctx TKType WithType.no_value (CRToplevel None) (String.concat "." sl,p0) p0
|
|
|
end;
|
|
|
- raise e
|
|
|
+ raise_error e
|
|
|
in
|
|
|
|
|
|
(* loop through the given EField expression to figure out whether it's a dot-path that we have to resolve,
|
|
@@ -626,8 +626,8 @@ and type_access ctx e p mode with_type =
|
|
|
begin match e1.eexpr with
|
|
|
| TTypeExpr (TClassDecl c) ->
|
|
|
begin match mode with
|
|
|
- | 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;
|
|
|
+ | MSet _ -> raise_typing_error "Cannot set constructor" p;
|
|
|
+ | MCall _ -> raise_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
|
|
@@ -656,7 +656,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)
|
|
|
- | _ -> typing_error "Binding new is only allowed on class types" p
|
|
|
+ | _ -> raise_typing_error "Binding new is only allowed on class types" p
|
|
|
end;
|
|
|
| EField _ ->
|
|
|
handle_efield ctx e p mode with_type
|
|
@@ -711,14 +711,14 @@ and type_vars ctx vl p =
|
|
|
DisplayEmitter.display_variable ctx v pv;
|
|
|
v,e
|
|
|
with
|
|
|
- Error (e,p,depth) ->
|
|
|
- check_error ctx e p depth;
|
|
|
+ Error err ->
|
|
|
+ check_error ctx err;
|
|
|
add_local ctx VGenerated n t_dynamic pv, None (* TODO: What to do with this... *)
|
|
|
) vl in
|
|
|
List.iter (fun (v,_) ->
|
|
|
delay_if_mono ctx PTypeField v.v_type (fun() ->
|
|
|
if ExtType.is_void (follow v.v_type) then
|
|
|
- typing_error "Variables of type Void are not allowed" v.v_pos
|
|
|
+ raise_typing_error "Variables of type Void are not allowed" v.v_pos
|
|
|
)
|
|
|
) vl;
|
|
|
match vl with
|
|
@@ -792,7 +792,7 @@ and format_string ctx s p =
|
|
|
if i = len then
|
|
|
match groups with
|
|
|
| [] -> die "" __LOC__
|
|
|
- | g :: _ -> typing_error ("Unclosed " ^ gname) { p with pmin = !pmin + g + 1; pmax = !pmin + g + 2 }
|
|
|
+ | g :: _ -> raise_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
|
|
@@ -811,8 +811,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 typing_error "Expression cannot be empty" ep
|
|
|
- else typing_error msg pos
|
|
|
+ if Lexer.string_is_whitespace scode then raise_typing_error "Expression cannot be empty" ep
|
|
|
+ else raise_typing_error msg pos
|
|
|
in
|
|
|
match ParserEntry.parse_expr_string ctx.com.defines scode ep error true with
|
|
|
| ParseSuccess(data,_,_) -> data
|
|
@@ -838,7 +838,7 @@ and type_block ctx el with_type p =
|
|
|
let rec loop acc = function
|
|
|
| [] -> List.rev acc
|
|
|
| e :: l ->
|
|
|
- let acc = try merge acc (type_expr ctx e (if l = [] then with_type else WithType.no_value)) with Error (e,p,depth) -> check_error ctx e p depth; acc in
|
|
|
+ let acc = try merge acc (type_expr ctx e (if l = [] then with_type else WithType.no_value)) with Error err -> check_error ctx err; acc in
|
|
|
loop acc l
|
|
|
in
|
|
|
let l = loop [] el in
|
|
@@ -886,7 +886,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 typing_error ("Duplicate field in object declaration : " ^ n) pn;
|
|
|
+ if PMap.mem n !fields then raise_typing_error ("Duplicate field in object declaration : " ^ n) pn;
|
|
|
let is_final = ref false in
|
|
|
let e = try
|
|
|
let t = match !dynamic_parameter with
|
|
@@ -907,7 +907,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 typing_error "Field names starting with a dollar are not allowed" p;
|
|
|
+ if starts_with n '$' then raise_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;
|
|
@@ -929,13 +929,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 typing_error ("Duplicate field in object declaration : " ^ f) pf;
|
|
|
+ if PMap.mem f acc then raise_typing_error ("Duplicate field in object declaration : " ^ f) pf;
|
|
|
let e = type_expr ctx e (WithType.named_structure_field f) in
|
|
|
- (match follow e.etype with TAbstract({a_path=[],"Void"},_) -> typing_error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
|
|
|
+ (match follow e.etype with TAbstract({a_path=[],"Void"},_) -> raise_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 typing_error "Field names starting with a dollar are not allowed" p;
|
|
|
+ if starts_with f '$' then raise_typing_error "Field names starting with a dollar are not allowed" p;
|
|
|
PMap.add f cf acc
|
|
|
end else acc)
|
|
|
in
|
|
@@ -1037,8 +1037,8 @@ and type_new ctx path el with_type force_inline p =
|
|
|
let fcc = unify_field_call ctx fa [] el p fa.fa_inline in
|
|
|
check_constructor_access ctx c fcc.fc_field p;
|
|
|
fcc
|
|
|
- with Error (e,p,depth) ->
|
|
|
- located_typing_error ~depth (error_msg p e);
|
|
|
+ with Error err ->
|
|
|
+ raise_typing_error_ext err
|
|
|
in
|
|
|
let display_position_in_el () =
|
|
|
List.exists (fun e -> DisplayPosition.display_position#enclosed_in (pos e)) el
|
|
@@ -1084,7 +1084,7 @@ and type_new ctx path el with_type force_inline p =
|
|
|
end
|
|
|
end
|
|
|
| mt ->
|
|
|
- typing_error ((s_type_path (t_infos mt).mt_path) ^ " cannot be constructed") p
|
|
|
+ raise_typing_error ((s_type_path (t_infos mt).mt_path) ^ " cannot be constructed") p
|
|
|
end
|
|
|
| Error _ as exc when display_position_in_el() ->
|
|
|
List.iter (fun e -> ignore(type_expr ctx e WithType.value)) el;
|
|
@@ -1098,17 +1098,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 -> typing_error msg p | None -> error_require r p)
|
|
|
+ | Var { v_read = AccRequire (r,msg) } -> (match msg with Some msg -> raise_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 typing_error "Only generic type parameters can be constructed" p;
|
|
|
+ if not (TypeloadCheck.is_generic_parameter ctx c) then raise_typing_error "Only generic type parameters can be constructed" p;
|
|
|
begin match get_constructible_constraint ctx tl p with
|
|
|
| None ->
|
|
|
- raise_typing_error (No_constructor (TClassDecl c)) p
|
|
|
+ raise_typing_error_ext (make_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
|
|
@@ -1121,9 +1121,9 @@ and type_new ctx path el with_type force_inline p =
|
|
|
let el = fcc.fc_args in
|
|
|
mk (TNew (c,params,el)) t p
|
|
|
| _ ->
|
|
|
- typing_error (s_type (print_context()) t ^ " cannot be constructed") p
|
|
|
- end with Error(No_constructor _ as err,p,depth) when ctx.com.display.dms_kind <> DMNone ->
|
|
|
- located_display_error ~depth ctx.com (error_msg p err);
|
|
|
+ raise_typing_error (s_type (print_context()) t ^ " cannot be constructed") p
|
|
|
+ end with Error ({ err_message = No_constructor _ } as err) when ctx.com.display.dms_kind <> DMNone ->
|
|
|
+ display_error_ext ctx.com err;
|
|
|
Diagnostics.secure_generated_code ctx (mk (TConst TNull) t p)
|
|
|
|
|
|
and type_try ctx e1 catches with_type p =
|
|
@@ -1156,7 +1156,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 typing_error "Catch class parameter must be Dynamic" p;
|
|
|
+ if Abstract.follow_with_abstracts pt != t_dynamic then raise_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) ->
|
|
@@ -1164,7 +1164,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) ->
|
|
|
- typing_error "Cannot catch non-generic type parameter" p
|
|
|
+ raise_typing_error "Cannot catch non-generic type parameter" p
|
|
|
| TInst (_,params) | TEnum (_,params) ->
|
|
|
check_catch_type_params params (snd th);
|
|
|
t
|
|
@@ -1174,7 +1174,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
|
|
|
- | _ -> typing_error "Catch type must be a class, an enum or Dynamic" (pos e_ast)
|
|
|
+ | _ -> raise_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);
|
|
@@ -1222,7 +1222,7 @@ and type_map_declaration ctx e1 el with_type p =
|
|
|
try
|
|
|
let p = Hashtbl.find keys e_key.eexpr in
|
|
|
display_error ctx.com "Duplicate key" e_key.epos;
|
|
|
- typing_error ~depth:1 (compl_msg "Previously defined here") p
|
|
|
+ raise_typing_error ~depth:1 (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;
|
|
@@ -1234,8 +1234,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));
|
|
|
- typing_error "Expected a => b" (pos e)
|
|
|
- | _ -> typing_error "Expected a => b" (pos e)
|
|
|
+ raise_typing_error "Expected a => b" (pos e)
|
|
|
+ | _ -> raise_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) ->
|
|
@@ -1279,7 +1279,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.com "Type parameters not supported in unnamed local functions" p;
|
|
|
- if with_type <> WithType.NoValue then typing_error "Type parameters are not supported for rvalue functions" p
|
|
|
+ if with_type <> WithType.NoValue then raise_typing_error "Type parameters are not supported for rvalue functions" p
|
|
|
end;
|
|
|
let v,pname = (match name with
|
|
|
| None -> None,p
|
|
@@ -1485,12 +1485,12 @@ and type_array_decl ctx el with_type p =
|
|
|
let el = List.map (fun e -> type_expr ctx e WithType.value) el in
|
|
|
let t = try
|
|
|
unify_min_raise ctx el
|
|
|
- with Error (Unify l,p,n) ->
|
|
|
+ with Error ({ err_message = Unify _ } as err) ->
|
|
|
if !allow_array_dynamic || ctx.untyped || ignore_error ctx.com then
|
|
|
t_dynamic
|
|
|
else begin
|
|
|
- display_error ctx.com "Arrays of mixed types are only allowed if the type is forced to Array<Dynamic>" p;
|
|
|
- raise (Error (Unify l, p,n))
|
|
|
+ display_error ctx.com "Arrays of mixed types are only allowed if the type is forced to Array<Dynamic>" err.err_pos;
|
|
|
+ raise_error err
|
|
|
end
|
|
|
in
|
|
|
mk (TArrayDecl el) (ctx.t.tarray t) p
|
|
@@ -1573,7 +1573,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 -> typing_error "Cannot return `null` from Void-function" p
|
|
|
+ | TConst TNull -> raise_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) *)
|
|
@@ -1584,8 +1584,9 @@ and type_return ?(implicit=false) ctx e with_type p =
|
|
|
]) t e.epos;
|
|
|
| _ ->
|
|
|
mk (TReturn (Some e)) (mono_or_dynamic ctx with_type p) p
|
|
|
- with Error(err,p,depth) ->
|
|
|
- check_error ctx err p depth;
|
|
|
+ with Error err ->
|
|
|
+ let p = err.err_pos in
|
|
|
+ check_error ctx err;
|
|
|
(* If we have a bad return, let's generate a return null expression at least. This surpresses various
|
|
|
follow-up errors that come from the fact that the function no longer has a return expression (issue #6445). *)
|
|
|
let e_null = mk (TConst TNull) (mk_mono()) p in
|
|
@@ -1597,14 +1598,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 -> ()
|
|
|
- | _ -> typing_error "Cast type parameters must be Dynamic" tpos
|
|
|
+ | _ -> raise_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 _ -> typing_error "Can't cast to a type parameter" tpos | _ -> ());
|
|
|
+ (match c.cl_kind with KTypeParameter _ -> raise_typing_error "Can't cast to a type parameter" tpos | _ -> ());
|
|
|
TClassDecl c
|
|
|
| TEnum (e,_) -> TEnumDecl e
|
|
|
| _ -> die "" __LOC__);
|
|
@@ -1614,7 +1615,7 @@ and type_cast ctx e t p =
|
|
|
| TAbstract (a,params) ->
|
|
|
loop (Abstract.get_underlying_type a params)
|
|
|
| _ ->
|
|
|
- typing_error "Cast type must be a class or an enum" tpos
|
|
|
+ raise_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
|
|
@@ -1635,7 +1636,7 @@ and make_if_then_else ctx e0 e1 e2 with_type p =
|
|
|
and type_if ctx e e1 e2 with_type is_ternary p =
|
|
|
let e = type_expr ctx e WithType.value in
|
|
|
if is_ternary then begin match e.eexpr with
|
|
|
- | TConst TNull -> typing_error "Cannot use null as ternary condition" e.epos
|
|
|
+ | TConst TNull -> raise_typing_error "Cannot use null as ternary condition" e.epos
|
|
|
| _ -> ()
|
|
|
end;
|
|
|
let e = AbstractCast.cast_or_unify ctx ctx.t.tbool e p in
|
|
@@ -1659,7 +1660,7 @@ 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,_,_) ->
|
|
|
- typing_error "Markup literals must be processed by a macro" p
|
|
|
+ raise_typing_error "Markup literals must be processed by a macro" p
|
|
|
| (Meta.Analyzer,_,_) ->
|
|
|
let e = e() in
|
|
|
{e with eexpr = TMeta(m,e)}
|
|
@@ -1818,15 +1819,15 @@ and type_call_builtin ctx e el mode with_type 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 typing_error "Cannot call super constructor outside class constructor" p;
|
|
|
+ if ctx.curfun <> FunConstructor then raise_typing_error "Cannot call super constructor outside class constructor" p;
|
|
|
let el, t = (match ctx.curclass.cl_super with
|
|
|
- | None -> typing_error "Current class does not have a super" p
|
|
|
+ | None -> raise_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
|
|
|
let t = TInst (c,params) in
|
|
|
let e = mk (TConst TSuper) t sp in
|
|
|
- if (Meta.has Meta.CompilerGenerated cf.cf_meta) then located_display_error ctx.com (error_msg p (No_constructor (TClassDecl c)));
|
|
|
+ if (Meta.has Meta.CompilerGenerated cf.cf_meta) then display_error ctx.com (error_msg (No_constructor (TClassDecl c))) p;
|
|
|
let fa = FieldAccess.create e cf (FHInstance(c,params)) false p in
|
|
|
let fcc = unify_field_call ctx fa [] el p false in
|
|
|
let el = fcc.fc_args in
|
|
@@ -1839,12 +1840,12 @@ and type_call_builtin ctx e el mode with_type p =
|
|
|
and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
|
|
|
match e with
|
|
|
| EField ((EConst (String(s,_)),ps),"code",EFNormal) ->
|
|
|
- if UTF8.length s <> 1 then typing_error "String must be a single UTF8 char" ps;
|
|
|
+ if UTF8.length s <> 1 then raise_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 '$' ->
|
|
|
- typing_error "Field names starting with $ are not allowed" p
|
|
|
+ raise_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 typing_error "Cannot use super as value" p;
|
|
|
+ if s = "super" && with_type <> WithType.NoValue && not ctx.in_display then raise_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
|
|
|
| EField _
|
|
@@ -1862,9 +1863,9 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
|
|
|
(match suffix with
|
|
|
| "i32" ->
|
|
|
(try mk (TConst (TInt (Int32.of_string s))) ctx.com.basic.tint p
|
|
|
- with _ -> typing_error ("Cannot represent " ^ s ^ " with a 32 bit integer") p)
|
|
|
+ with _ -> raise_typing_error ("Cannot represent " ^ s ^ " with a 32 bit integer") p)
|
|
|
| "i64" ->
|
|
|
- if String.length s > 18 && String.sub s 0 2 = "0x" then typing_error "Invalid hexadecimal integer" p;
|
|
|
+ if String.length s > 18 && String.sub s 0 2 = "0x" then raise_typing_error "Invalid hexadecimal integer" p;
|
|
|
|
|
|
let i64 = Int64.of_string s in
|
|
|
let high = Int64.to_int32 (Int64.shift_right i64 32) in
|
|
@@ -1880,11 +1881,11 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
|
|
|
| "u32" ->
|
|
|
let check = ECheckType ((EConst (Int (s, None)), p), (CTPath (mk_type_path ([],"UInt")), p)), p in
|
|
|
type_expr ctx check with_type
|
|
|
- | other -> typing_error (other ^ " is not a valid integer suffix") p)
|
|
|
+ | other -> raise_typing_error (other ^ " is not a valid integer suffix") p)
|
|
|
| EConst (Float (s, Some suffix) as c) ->
|
|
|
(match suffix with
|
|
|
| "f64" -> Texpr.type_constant ctx.com.basic c p
|
|
|
- | other -> typing_error (other ^ " is not a valid float suffix") p)
|
|
|
+ | other -> raise_typing_error (other ^ " is not a valid float suffix") p)
|
|
|
| EConst c ->
|
|
|
Texpr.type_constant ctx.com.basic c p
|
|
|
| EBinop (OpNullCoal,e1,e2) ->
|
|
@@ -2011,8 +2012,8 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
|
|
|
| EThrow e ->
|
|
|
let e = try
|
|
|
type_expr ctx e WithType.value
|
|
|
- with Error(e,p',depth) ->
|
|
|
- check_error ctx e p' depth;
|
|
|
+ with Error err ->
|
|
|
+ check_error ctx err;
|
|
|
Texpr.Builder.make_null t_dynamic p
|
|
|
in
|
|
|
mk (TThrow e) (mono_or_dynamic ctx with_type p) p
|
|
@@ -2145,12 +2146,12 @@ let rec create com =
|
|
|
ctx.g.std <- (try
|
|
|
TypeloadModule.load_module ctx ([],"StdTypes") null_pos
|
|
|
with
|
|
|
- Error (Module_not_found ([],"StdTypes"),_,_) ->
|
|
|
+ Error { err_message = Module_not_found ([],"StdTypes") } ->
|
|
|
try
|
|
|
let std_path = Sys.getenv "HAXE_STD_PATH" in
|
|
|
- typing_error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
|
|
|
+ raise_typing_error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
|
|
|
with Not_found ->
|
|
|
- typing_error "Standard library not found. You may need to set your `HAXE_STD_PATH` environment variable" null_pos
|
|
|
+ raise_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_imports <- List.map (fun t -> t,null_pos) ctx.g.std.m_types;
|
|
@@ -2218,4 +2219,4 @@ make_call_ref := make_call;
|
|
|
type_call_target_ref := type_call_target;
|
|
|
type_access_ref := type_access;
|
|
|
type_block_ref := type_block;
|
|
|
-create_context_ref := create
|
|
|
+create_context_ref := create
|