Data encoding: fail on string_enum that should be a constant
This commit is contained in:
parent
c77cbcb30b
commit
f00c7c0667
@ -535,7 +535,10 @@ module Encoding = struct
|
||||
let array e = dynamic_size (Variable.array e)
|
||||
let list e = dynamic_size (Variable.list e)
|
||||
|
||||
let string_enum cases =
|
||||
let string_enum = function
|
||||
| [] -> invalid_arg "data_encoding.string_enum: cannot have zero cases"
|
||||
| [ _case ] -> invalid_arg "data_encoding.string_enum: cannot have a single case, use constant instead"
|
||||
| _ :: _ as cases ->
|
||||
let arr = Array.of_list (List.map snd cases) in
|
||||
let tbl = Hashtbl.create (Array.length arr) in
|
||||
List.iteri (fun ind (str, a) -> Hashtbl.add tbl a (str, ind)) cases ;
|
||||
|
Loading…
Reference in New Issue
Block a user