Skip to content

Commit

Permalink
improved macro error reporting (close HaxeFoundation#3566)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Feb 22, 2015
1 parent 99dfcda commit 47d6e44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ open Type
open Common
open Typecore

let locate_macro_error = ref true

(*
Build module structure : should be atomic - no type loading is possible
*)
Expand Down Expand Up @@ -1665,9 +1667,10 @@ let init_class ctx c p context_init herits fields =
on_error = (fun ctx msg ep ->
ctx.com.error msg ep;
(* macros expressions might reference other code, let's recall which class we are actually compiling *)
if ep.pfile <> c.cl_pos.pfile then ctx.com.error "Defined in this class" c.cl_pos
if !locate_macro_error && (ep.pfile <> c.cl_pos.pfile || ep.pmax < c.cl_pos.pmin || ep.pmin > c.cl_pos.pmax) then ctx.com.error "Defined in this class" c.cl_pos
);
} in
locate_macro_error := true;
incr stats.s_classes_built;
let fields = patch_class ctx c fields in
let fields = ref fields in
Expand Down
9 changes: 7 additions & 2 deletions typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3941,9 +3941,14 @@ and build_call ctx acc el (with_type:with_type) p =
ctx.with_type_stack <- List.tl ctx.with_type_stack;
let old = ctx.on_error in
ctx.on_error <- (fun ctx msg ep ->
old ctx msg ep;
(* display additional info in the case the error is not part of our original call *)
if ep.pfile <> p.pfile || ep.pmax < p.pmin || ep.pmin > p.pmax then old ctx "Called from macro here" p
if ep.pfile <> p.pfile || ep.pmax < p.pmin || ep.pmin > p.pmax then begin
Typeload.locate_macro_error := false;
old ctx msg ep;
Typeload.locate_macro_error := true;
ctx.com.error "Called from macro here" p;
end else
old ctx msg ep;
);
let e = try
f()
Expand Down

0 comments on commit 47d6e44

Please sign in to comment.