Proto/Michelson: fix injectivity of types
Because some type parameters of the type ty
are abstract, the OCaml typechecker cannot prove that some types are different, e.g. z num
and Tez.t
. This leads to impossible cases in pattern matching that have to be covered with assert false
. This is dangerous because we may forget to treat new cases when adding new types.
A solution is to make sure OCaml typechecker can distinguish all types used as type parameter of ty
. A simple but unfortunately syntactically a bit heavy is to box them with a public constructor, e.g. type tez = Tez of Tez.t [@@ocaml.unboxed]
(the annotation allow to have a zero runtime and memory cost)