Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OCaml 4.04.2 Compiler Bug
module type Int = sig
val one : int
val (+) : int -> int -> int
end
module Make (Int : Int) = struct
(* this assertion must fail in order to make the linker command fail *)
let () = assert false
(* this assertion doesn't matter *)
let () =
let falsy () = [1] == [1] in
assert (falsy ())
(* both the list and the + are needed to get the linker command to fail *)
let two () = [ Int.(one + one) ]
end
module M = Make(struct
let one = 1
let (+) = (+)
end)
(* This programs fails with a linker error on OCaml version 4.04.2 but not 4.05.0
{[
% jbuilder build @install
ocamldep src/main.depends.ocamldep-output
ocamlc src/main.{cmi,cmo,cmt}
ocamlopt src/main.{cmx,o}
ocamlopt src/main.exe (exit 2)
(cd _build/default && ~/.opam/4.04.2/bin/ocamlopt.opt -w -40 -g -o src/main.exe src/main.cmx)
src/main.o: In function `camlMain__entry':
~/.../_build/default/src/main.ml:24: undefined reference to `camlMain__two_1207'
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
]}
*)
let _ = M.two ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.