I think you have the right diagnosis. Going a step further, it appears that the type-based disambiguation of the record field doesn’t work when given a closed variant type. Your example works fine if we write foo
instead of [< foo]
in the type of (the function) foo
’s argument.
We see the same behavior in code like the following:
# module M = struct type t = M end;;
module M : sig type t = M end
# type t = [ `M of M.t ];;
type t = [ `M of M.t ]
# let f : [< t ] -> unit = function | `M M -> ();;
Line 1, characters 39-40:
Error: Unbound constructor M
I don’t know if this can be improved, but it might be good to make a GitHub issue just to see if it’s possible.