Thread overview
[Issue 5714] case ranges in final switches
May 22, 2018
Dmitry Olshansky
Aug 09, 2020
Walter Bright
Dec 17, 2022
Iain Buclaw
Jan 21, 2023
Nick Treleaven
Jul 02
Bolpat
May 22, 2018
https://issues.dlang.org/show_bug.cgi?id=5714

Dmitry Olshansky <dmitry.olsh@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |bootcamp
                 CC|                            |dmitry.olsh@gmail.com

--
August 09, 2020
https://issues.dlang.org/show_bug.cgi?id=5714

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=5713

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=5714

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P4

--
January 21, 2023
https://issues.dlang.org/show_bug.cgi?id=5714

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #4 from Nick Treleaven <nick@geany.org> ---
(In reply to Andrej Mitrovic from comment #1)
> And it also limits the number of cases to 256 (for optimization purposes?).
> 
> So a final switch would only work on byte-types.

See issue 15279 which seems to be an implementation issue rather than a design decision (the pull comment suggests lowering case range statements to an if/else instead).

--
July 02
https://issues.dlang.org/show_bug.cgi?id=5714

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--- Comment #5 from Bolpat <qs.il.paperinik@gmail.com> ---
The limitation of the number of `case` labels is entirely orthogonal to allowing case ranges for `final switch`, as the ranges are just syntactic sugar for writing them out.

This errors:
---
void main()
{
    ubyte u;
    final switch (u)
    {
        case   0: .. case 100: break;
        case 101: .. case 255: break;
    }
}
---

This is fine:
---
void main() {
    ubyte u;
    Lswitch: final switch (u)
    {
        static foreach (i; 0 .. 100 + 1)
        {
            case i: break Lswitch;
        }
        static foreach (i; 101 .. 255 + 1)
        {
            case i: break Lswitch;
        }
    }
}
---

The error makes no sense. It might have made sense in 2011, but in 2024, it just requires some boilerplate to work.

--