forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ocaml#80 from mshinwell/fb-backport-pr10205
Backport PR#10205 from upstream
- Loading branch information
Showing
4 changed files
with
142 additions
and
84 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
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
68 changes: 68 additions & 0 deletions
68
ocaml/testsuite/tests/basic-modules/recursive_module_init.ml
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,68 @@ | ||
(* TEST *) | ||
|
||
let check ~stub txt f = | ||
let run mode f = | ||
match f mode with | ||
| n -> string_of_int n | ||
| exception Undefined_recursive_module _ -> "__" in | ||
Printf.printf "%5s[%s]: nonrec => %s, self => %s, mod => %s\n%!" | ||
txt | ||
(if f == stub then "stub" else "real") | ||
(run `Nonrec f) | ||
(run `Self f) | ||
(run `Mod f) | ||
|
||
module rec M : sig | ||
val f1 : [`Nonrec|`Self|`Mod] -> int | ||
val f2 : [`Nonrec|`Self|`Mod] -> int | ||
val f3 : [`Nonrec|`Self|`Mod] -> int | ||
val f4 : unit -> [`Nonrec|`Self|`Mod] -> int | ||
val f5 : unit -> [`Nonrec|`Self|`Mod] -> int | ||
end = struct | ||
let rec f1 mode = | ||
match mode with | ||
| `Nonrec -> 42 | ||
| `Self -> f1 `Nonrec | ||
| `Mod -> M.f1 `Nonrec | ||
let f2 = f1 | ||
let f3 = M.f1 | ||
let f4 () = f1 | ||
let f5 () = M.f1 | ||
|
||
let () = | ||
check ~stub:f3 "f1" f1; | ||
check ~stub:f3 "f2" f2; | ||
check ~stub:f3 "f3" f3; | ||
check ~stub:f3 "f4" (f4 ()); | ||
check ~stub:f3 "f5" (f5 ()) | ||
end | ||
|
||
let () = | ||
check ~stub:M.f3 "M.f1" M.f1; | ||
check ~stub:M.f3 "M.f2" M.f2; | ||
check ~stub:M.f3 "M.f3" M.f3; | ||
check ~stub:M.f3 "M.f4" (M.f4 ()); | ||
check ~stub:M.f3 "M.f5" (M.f5 ()) | ||
|
||
|
||
module rec Foo : sig | ||
class cls : object | ||
method go : unit | ||
end | ||
module M : sig | ||
val foo : unit -> cls | ||
val bar : cls Lazy.t | ||
end | ||
end = struct | ||
class cls = object | ||
method go = print_endline "go" | ||
end | ||
module M = struct | ||
let foo () = new Foo.cls | ||
let bar = lazy (foo ()) | ||
end | ||
end | ||
|
||
let () = | ||
List.iter (fun x -> x#go) | ||
[new Foo.cls; Foo.M.foo(); Lazy.force Foo.M.bar] |
13 changes: 13 additions & 0 deletions
13
ocaml/testsuite/tests/basic-modules/recursive_module_init.reference
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,13 @@ | ||
f1[real]: nonrec => 42, self => 42, mod => __ | ||
f2[real]: nonrec => 42, self => 42, mod => __ | ||
f3[stub]: nonrec => __, self => __, mod => __ | ||
f4[real]: nonrec => 42, self => 42, mod => __ | ||
f5[stub]: nonrec => __, self => __, mod => __ | ||
M.f1[real]: nonrec => 42, self => 42, mod => 42 | ||
M.f2[real]: nonrec => 42, self => 42, mod => 42 | ||
M.f3[stub]: nonrec => 42, self => 42, mod => 42 | ||
M.f4[real]: nonrec => 42, self => 42, mod => 42 | ||
M.f5[real]: nonrec => 42, self => 42, mod => 42 | ||
go | ||
go | ||
go |