Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch missing standard library in init macros #11621

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core/error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ let raise_msg ?(depth = 0) msg p = raise_error_msg ~depth (Custom msg) p
let raise_typing_error ?(depth = 0) msg p = raise_msg ~depth msg p
let raise_typing_error_ext err = raise_error err

let raise_std_not_found () =
try
let std_path = Sys.getenv "HAXE_STD_PATH" in
raise_typing_error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
with Not_found ->
raise_typing_error "Standard library not found. You may need to set your `HAXE_STD_PATH` environment variable" null_pos

let error_require r p =
if r = "" then
raise_typing_error "This field is not available with the current compilation flags" p
Expand Down
5 changes: 4 additions & 1 deletion src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,10 @@ let create_macro_context com =
[cp#clone]
) com.class_paths#as_list;
(* Eval _std must be in front so we don't look into hxnodejs or something. *)
com2.class_paths#add (Option.get !eval_std);
(* This can run before `TyperEntry.create`, so in order to display nice error when std is not found, this needs to be checked here too *)
(match !eval_std with
| Some std -> com2.class_paths#add std
| None -> Error.raise_std_not_found ());
let defines = adapt_defines_to_macro_context com2.defines; in
com2.defines.values <- defines.values;
com2.defines.defines_signature <- None;
Expand Down
6 changes: 1 addition & 5 deletions src/typing/typerEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ let create com macros =
TypeloadModule.load_module ctx ([],"StdTypes") null_pos
with
Error { err_message = Module_not_found ([],"StdTypes") } ->
try
let std_path = Sys.getenv "HAXE_STD_PATH" in
raise_typing_error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
with Not_found ->
raise_typing_error "Standard library not found. You may need to set your `HAXE_STD_PATH` environment variable" null_pos
Error.raise_std_not_found ()
);
(* We always want core types to be available so we add them as default imports (issue #1904 and #3131). *)
List.iter (fun mt ->
Expand Down