Skip to content

Commit f0fd752

Browse files
committed
support importing module-level statics
1 parent 2d7bc8e commit f0fd752

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/typing/typeloadModule.ml

+18-3
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,28 @@ let init_module_type ctx context_init (decl,p) =
545545
ctx.m.module_types <- ((match name with None -> tsub | Some(n,pname) -> rebind tsub n pname),p) :: ctx.m.module_types
546546
with Not_found ->
547547
(* this might be a static property, wait later to check *)
548-
let tmain = get_type tname in
549-
context_init#add (fun() ->
548+
let find_main_type_static () =
549+
let tmain = get_type tname in
550550
try
551551
add_static_init tmain name tsub
552552
with Not_found ->
553+
(* TODO: mention module-level declarations in the error message? *)
553554
display_error ctx (s_type_path (t_infos tmain).mt_path ^ " has no field or subtype " ^ tsub) p
554-
))
555+
in
556+
context_init#add (fun() ->
557+
match md.m_statics with
558+
| Some c ->
559+
(try
560+
ignore(c.cl_build());
561+
let _ = List.find (fun cf -> cf.cf_name = tsub) c.cl_ordered_statics in
562+
let imported_name = match name with None -> tsub | Some (n,pname) -> n in
563+
ctx.m.module_globals <- PMap.add imported_name (TClassDecl c,tsub,p) ctx.m.module_globals;
564+
with Not_found ->
565+
find_main_type_static ())
566+
| None ->
567+
find_main_type_static ()
568+
)
569+
)
555570
| (tsub,p2) :: (fname,p3) :: rest ->
556571
(match rest with
557572
| [] -> ()

0 commit comments

Comments
 (0)