-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(* This test monitors an example that caused an earlier version of the library | ||
to segfault. We keep it as regression test. | ||
This test was contributed by @v-gb. *) | ||
|
||
module type S = sig | ||
type t | ||
|
||
val t : t | ||
end | ||
|
||
type (_, _, _) Provider.Trait.t += | ||
| A : | ||
'something Base.Type_equal.Id.t | ||
-> (_, (module S with type t = 'something), [> `A ]) Provider.Trait.t | ||
|
||
let id_int = Type_equal.Id.create ~name:"int" [%sexp_of: int] | ||
let id_string = Type_equal.Id.create ~name:"string" [%sexp_of: string] | ||
|
||
let impl (type a) id value = | ||
Provider.Trait.implement | ||
(A id) | ||
~impl: | ||
(module struct | ||
type t = a | ||
|
||
let t = value | ||
end) | ||
;; | ||
|
||
let%expect_test "magic" = | ||
let handler = | ||
Provider.Handler.make | ||
[ (if true then impl id_int 1 else impl id_string "" [@coverage off]) ] | ||
in | ||
require_does_raise [%here] (fun () -> | ||
(let module M = (val Provider.Handler.lookup handler ~trait:(A id_string)) in | ||
print_string M.t) [@coverage off]); | ||
[%expect | ||
{| | ||
("Invalid usage of [Provider.Trait]: Extensible variants with the same id are expected to be physically equal through the use of this library" | ||
(( | ||
trait ( | ||
(id #id) | ||
(name Provider_test.Test__magic.A))))) | ||
|}]; | ||
() | ||
;; |
Empty file.