# Pattern matching + Enum proposals

**URL:** <https://forum.modular.com/t/pattern-matching-enum-proposals/3473>\
**Category:** Language Design\
**Tags:** discussion\
**Created:** [September 7, 2026, 2:54am UTC](https://forum.modular.com/t/pattern-matching-enum-proposals/3473 "2026-09-07T02:54:29Z")\
**Posts on this page:** 1\
**Showing post:** 78

<div class="post-metadata">

**Author:** ![clattner](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/clattner/32/201_2.png) [@clattner](https://forum.modular.com/u/clattner)\
**Post date:** [November 9, 2026, 1:22am UTC](https://forum.modular.com/t/pattern-matching-enum-proposals/3473/78 "2026-11-09T01:22:13Z")

</div>

> After playing around with the new syntax, it appears that a few LLMs (Qwen 3.8 27B, GPT 6 Luna, Nemotron 3 Ultra (because it’s free)) are making the assumption that there is no tag on the union and that they can do pointer casts between the union and the union’s members.

I’m not particularly worried about this, the proposal isn’t even implemented or documented yet - I wouldn’t expect LLMs to know this, nor do we expect LLMs to transfer other languages onto Mojo as the way to support it. It’s nice when it works out, but that isn’t the core strategy.

> Do you have a vision for how the C ABI compatible `union` will be expressed? I don’t see a good place to put that if the goal is to eventually unify `union` and `Union`.

This isn’t designed at all, but I imagine that something like:

```auto
@unsafe_untagged_union
union BitMash:
   case F(Float32)
   case I(Int32)

```

would be analogous to:

```auto
union BitMash {
  float F;
  int32_t I;
};

```

Because there is no tag, you can’t pattern match on it of course.

* * *

> However, it doesn’t (yet) address the performance concerns in my earlier posts. Most notably, the “tagless Shape” type I benchmarked in my earlier posts is a **safe** tagless union (here “tagless” means “no dedicated tag field”),

Hi Nick,

That’s right; this proposal doesn’t solve all the possible things one might want to do. On another thread [Anatoly brought up](https://forum.modular.com/t/companion-proposal-inductive-enums-and-structural-recursion/3570) another interesting use-case that isn’t directly covered by the design. I consider this to be perfectly acceptable - this approach is basically saying “there are two different ADTs that desugar to structs”, but there can be more in the future. As with that work, I’d recommend using Mojo’s powerful metaprogramming and trait inheritance features to explore the capabilities of the core language, and if specific use-cases gain traction, we can figure out the best way to sugar them in the future.

To clarify one potential point of confusion - there is nothing in the `union` proposal that forces storage as a `Tuple`, and simple element fields should definitely not be stored as `Tuple[OneType]`. Swift has a plethora of bitstealing optimizations for ADTs; I’d expect Mojo to replicate and build on the same.

-Chris

---

_[View the full topic](https://forum.modular.com/t/pattern-matching-enum-proposals/3473)._
