Thread overview
[Issue 19960] ElementType!(char[]) + betterC = wrong type
Jun 04, 2022
Walter Bright
Dec 17, 2022
Iain Buclaw
Jan 15, 2023
Walter Bright
Jan 15, 2023
Richard Cattermole
June 04, 2022
https://issues.dlang.org/show_bug.cgi?id=19960

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |betterC
                 CC|                            |bugzilla@digitalmars.com

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

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

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
I'm getting an output of `void`.

The implementation of this is in std.range.primitive, and is:

  template ElementType(R)
  {
    static if (is(typeof(R.init.front.init) T))
        alias ElementType = T;
    else
        alias ElementType = void;
  }

What is happening is R.init.front.init is failing to compile, hence the `void` result. It is falling victim to the autodecoder, which can be seen by compiling it as regular D code, and the output is `dchar`, not `char`. The `dchar` comes about from the autodecoding, and we're stuck with that at the moment.

Autodecoding is never going to work with betterC, because it uses the GC and throws exceptions. So I don't know how to fix this.

If we change the `char` to `ubyte`, it works and prints `ubyte`.

If we ever do remove autodecoding, this bug report should resolve itself.

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

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alphaglosined@gmail.com

--- Comment #2 from Richard Cattermole <alphaglosined@gmail.com> ---
> Autodecoding is never going to work with betterC, because it uses the GC and throws exceptions. So I don't know how to fix this.

Assert; this affects far too much at compile time to not have it work even if it would if given the wrong input crash a program.

One option might be value-type exceptions if I ever get around to finishing the DIP. But I'm not keen on the idea of changing the exception mechanism depending on compiler flags for code like this, so it would be an all-or-nothing change.

--