c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Bitstruct restrictive casting

Open cbuttner opened this issue 1 year ago • 2 comments

bitstruct Foo : int {
  bool a;
}

bitstruct Bar : int {
  bool a;
  bool b;
}

fn void bitstruct_cast() {
  Bar bar;
  Foo foo = (Foo)(int)bar;
  //        ^^^^^^^^^^^^^
  // Error: You cannot cast 'Bar' to 'Foo'

  // This is fine:
  int bar_int = (int)bar;
  Foo foo = (Foo)bar_int;
}

Is this intentional or a bug?

cbuttner avatar Feb 26 '24 21:02 cbuttner

Actually I forgot bitcast could also be applied here. But this is still a little confusing.

cbuttner avatar Feb 26 '24 21:02 cbuttner

That looks like a bug.

lerno avatar Feb 26 '24 22:02 lerno

Does this work now?

lerno avatar Mar 26 '24 16:03 lerno

Looks good now, thanks.

cbuttner avatar Apr 09 '24 13:04 cbuttner