// Only for union type. Returns the index of the union member
// corresponding to the discriminator. If not found returns the
// default index or -1 if there is no default index.
int currentUnionMemberIndex(Any discriminatorValue) throws BadKind {
if (_kind != TCKind._tk_union)
throw new BadKind();
try {
for (int i=0; i<member_count(); i++) {
if (member_label(i).equal(discriminatorValue)) {
return i;