# @enumFromInt changed

**URL:** <https://ziggit.dev/t/enumfromint-changed/18633>\
**Category:** Explain\
**Created:** [November 29, 2026, 4:57pm UTC](https://ziggit.dev/t/enumfromint-changed/18633 "2026-11-29T16:57:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [November 29, 2026, 4:57pm UTC](https://ziggit.dev/t/enumfromint-changed/18633/1 "2026-11-29T16:57:59Z")

</div>

` @enumFromInt`, which is deprecated is more flexible than `@fromBackingInt`.  
The latter one only excepts an int of the correct size.  
Understandable but also a bit inconvenient. Is the inflexibility intended?  
Did we lose the flexibility of the deprecated version?

---

<div class="post-metadata">

**Author:** ![alanza](https://ziggit.dev/user_avatar/ziggit.dev/alanza/32/6006_2.png) [@alanza](https://ziggit.dev/u/alanza)\
**Post date:** [November 29, 2026, 5:21pm UTC](https://ziggit.dev/t/enumfromint-changed/18633/2 "2026-11-29T17:21:04Z")

</div>

If you have an int of the wrong size, you can use casting or truncating builtins like `@intCast()`, since `@fromBackingInt()` knows the size of integer to expect.

---

<div class="post-metadata">

**Author:** ![Justus2308](https://ziggit.dev/user_avatar/ziggit.dev/justus2308/32/5305_2.png) [@Justus2308](https://ziggit.dev/u/Justus2308)\
**Post date:** [November 29, 2026, 6:23pm UTC](https://ziggit.dev/t/enumfromint-changed/18633/3 "2026-11-29T18:23:08Z")

</div>

The change was intentional. `@enumFromInt` silently performed an `@intCast` on its arg anyway, now it’s explicit. Since `@fromBackingInt` provides a result type to its arg you no longer have to manually provide one with e.g. `@as` if you want to `@truncate` instead of the implicit int cast or if you have something like this:

```zig
const Enum = enum(u8) {
    a,
    b,
    c,
};

fn foo(x: u32) Enum {
    // The switch prongs would peer resolve to `comptime_int` if there was no `u8` result type,
    // resulting in a compile error as `comptime_int` is a comptime-only type ...
    return @fromBackingInt(switch (x) {
        123 => 0,
        456 => 1,
        789 => 2,
        else => unreachable,
    });
}

fn bar(x: u32) Enum {
    // ... which is exactly what happens with `@enumFromInt`. We get a compile error!
    return @enumFromInt(switch (x) {
        123 => 0,
        456 => 1,
        789 => 2,
        else => unreachable,
    });
}

```
