Skip to content

Commit

Permalink
Fix Interface.implements (should not raise)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Feb 19, 2024
1 parent 75e65b3 commit 1face98
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
28 changes: 15 additions & 13 deletions src/provider.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,21 @@ module Interface = struct
-> b
=
fun t ~class_id ~update_cache ~if_not_found ~if_found ->
if Array.length t = 0 then not_implemented ~class_info:(Class_id.info class_id);
let (Class.T { class_id = cached_id; implementation }) = t.(0) in
if Class_id.same class_id cached_id
then if_found (Stdlib.Obj.magic implementation)
else
binary_search
t
~class_id
~update_cache
~if_not_found
~if_found
~from:1
~to_:(Array.length t - 1)
if Array.length t = 0
then if_not_found ~class_info:(Class_id.info class_id)
else (
let (Class.T { class_id = cached_id; implementation }) = t.(0) in
if Class_id.same class_id cached_id
then if_found (Stdlib.Obj.magic implementation)
else
binary_search
t
~class_id
~update_cache
~if_not_found
~if_found
~from:1
~to_:(Array.length t - 1))
;;

let lookup t ~class_id =
Expand Down
20 changes: 7 additions & 13 deletions test/test__introspection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ let print_implements (Provider.T { t = _; interface }) =
let%expect_test "introspection" =
require_does_not_raise [%here] (fun () ->
print_implements (Provider.T { t = (); interface = Provider.Interface.make [] });
[%expect.unreachable]);
[%expect
{|
(* CR require-failed: repo/provider/test/test__introspection.ml:29:25.
Do not 'X' this CR; instead make the required property true,
which will make the CR disappear. For more information, see
[Expect_test_helpers_base.require]. *)
("unexpectedly raised" (
"Class not implemented" ((
class_info (
(id #id)
(name
Provider_test__Interface__Directory_reader.Provider_interface.Directory_reader)))))) |}];
[%expect
{|
((
implements (
(file_reader false)
(directory_reader false)))) |}]);
[%expect {||}];
let unix_reader = Providers.Unix_reader.make () in
Eio_main.run
@@ fun env ->
Expand Down

0 comments on commit 1face98

Please sign in to comment.