Skip to content

Unexpected behavior with Arrays as the object of Union #11

@jeff1010322

Description

@jeff1010322

Describe the bug

When a Union switch is defined with an array as the object for one of the case statements the generated code does not always keep the list.

Go and Rust do not ever seem to keep the list, but Javascript seems to work for some types.

I tested with 3 types of arrays, Opaque, strings, and unsigned hyper.

To Reproduce

Example IDL definition:

  enum CategoryType
  {
    NONE = 0,
    BYTES = 1,
    STRINGS = 2,
    INTS = 3
  };

  union Category switch (CategoryType Type)
  {
    case NONE:
      void;
    case BYTES:
      opaque bytes<>;
    case STRINGS:
      string strings<>;
    case INTS:
      unsigned hyper ints<>;
  };

Generated Go:

// Category generated union
type Category struct {
	Type CategoryType

	Bytes *byte

	Strings *string

	Ints *uint64
}

Generated Rust:

#[derive(PartialEq, Clone, Debug, XDROut, XDRIn)]
pub enum Category {
    NONE(()),

    BYTES(u8),

    STRINGS(String),

    INTS(u64),
}

Generated JS:

function Category() {
    return new _xdrJsSerialize2.default.Union(CategoryType(), {

        "NONE": () => {
            return new _xdrJsSerialize2.default.Void();
        },

        "BYTES": () => {
            return new _xdrJsSerialize2.default.VarOpaque(2147483647);
        },

        "STRINGS": () => {
            return new _xdrJsSerialize2.default.Str('', 2147483647);
        },

        "INTS": () => {
            return new _xdrJsSerialize2.default.VarArray(2147483647, () => new _xdrJsSerialize2.default.UHyper());
        }

    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions