Skip to content

Commit 787840b

Browse files
committed
feat: Include Prelude/Prepare and shadow them
instead of just `open`. This restores the toplevel output on values defined in Prelude, and forbids access to the interface of Prepare (which were two small regressions with pre-compilation).
1 parent eaad14c commit 787840b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/app/learnocaml_exercise_main.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,17 @@ let () =
129129
Learnocaml_toplevel.load_cmi_from_string top
130130
Learnocaml_exercise.(decipher File.prepare_cmi exo) >>= fun _ ->
131131
Learnocaml_toplevel.load_js ~print_outcome:false top
132-
~message: [%i"loading the prelude..."]
133132
exercise_js
134133
>>= fun r ->
135134
if not r then Lwt.fail_with [%i"error in prelude"] else
136-
Learnocaml_toplevel.load top "open! Prelude ;;" >>= fun r ->
135+
Learnocaml_toplevel.load top "include Prelude ;;"
136+
~message: [%i"loading the prelude..."] >>= fun r ->
137137
if not r then Lwt.fail_with [%i"error in prelude"] else
138-
Learnocaml_toplevel.load top "open! Prepare ;;" >>= fun r ->
138+
Learnocaml_toplevel.load ~print_outcome:false top "module Prelude = struct end;;" >>= fun r ->
139+
if not r then Lwt.fail_with [%i"error in prelude"] else
140+
Learnocaml_toplevel.load ~print_outcome:false top "include Prepare ;;" >>= fun r ->
141+
if not r then Lwt.fail_with [%i"error in prelude"] else
142+
Learnocaml_toplevel.load ~print_outcome:false top "module Prepare = struct end;;" >>= fun r ->
139143
if not r then Lwt.fail_with [%i"error in prelude"] else
140144
(* TODO: maybe remove Prelude, Prepare modules from the env ? *)
141145
Learnocaml_toplevel.set_checking_environment top >>= fun () ->

src/grader/grading.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ let get_grade
115115
};
116116
117117
handle_error (internal_error [%i"while preparing the tests"]) @@
118-
Toploop_ext.use_string ~print_outcome:false ~ppf_answer {|open! Prelude|};
118+
Toploop_ext.use_string ~print_outcome ~ppf_answer
119+
{|include Prelude|};
119120
handle_error (internal_error [%i"while preparing the tests"]) @@
120-
Toploop_ext.use_string ~print_outcome:false ~ppf_answer {|open! Prepare|};
121-
121+
Toploop_ext.use_string ~print_outcome:false ~ppf_answer
122+
{|module Prelude = struct end|};
123+
handle_error (internal_error [%i"while preparing the tests"]) @@
124+
Toploop_ext.use_string ~print_outcome:false ~ppf_answer
125+
{|include Prepare|};
126+
Toploop_ext.use_string ~print_outcome:false ~ppf_answer
127+
{|module Prepare = struct end|};
122128
123129
set_progress [%i"Loading your code."] ;
124130
handle_error user_code_error @@

0 commit comments

Comments
 (0)