Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior with Arrays as the object of Union #11

Open
jeff1010322 opened this issue Dec 3, 2019 · 1 comment
Open

Unexpected behavior with Arrays as the object of Union #11

jeff1010322 opened this issue Dec 3, 2019 · 1 comment

Comments

@jeff1010322
Copy link
Member

jeff1010322 commented Dec 3, 2019

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());
        }

    });
}
@kbartush
Copy link
Contributor

kbartush commented Dec 3, 2019

This should work, but until it is fixed you can just used a typedef to get the type you want in the union.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants