I'm going to be using ML syntax here, but not sure if this is an issue specific to the ml API. If you declare your types using Z3.Datatype.mk_datatypes (so no type parameters), but reference them using type parameters, Z3 segfaults instead of erroring out. This is the stack trace:
Datatype::util::get_sort_size(ref_vector<sort, ast_manager> const&, sort*) () from 4.15.4/install/lib/libz3.so
Datatype::util::compute_datatype_size_functions(svector<symbol, unsigned int> const&) () from 4.15.4/install/lib/libz3.so
Datatype::decl::plugin::end_def_block() () from 4.15.4/install/lib/libz3.so
Datatype::decl::plugin::mk_datatypes(unsigned int, datatype::def* const*, unsigned int, sort* const*, ref_vector<sort, ast_manager>&) ()
Happy to give more data if needed!