Thread overview
[Issue 20848] Bug in formatValueImpl
[Issue 20848] Bug in Nullable
May 20, 2020
Victor Porton
May 20, 2020
Victor Porton
May 20, 2020
Victor Porton
May 20, 2020
Victor Porton
Jul 13, 2020
Dlang Bot
Jan 28, 2021
Dlang Bot
May 20, 2020
https://issues.dlang.org/show_bug.cgi?id=20848

Victor Porton <porton@narod.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Bug in Nullable?            |Bug in Nullable

--
May 20, 2020
https://issues.dlang.org/show_bug.cgi?id=20848

--- Comment #1 from Victor Porton <porton@narod.ru> ---
A simpler test case:

///////////////////////////////
import std.typecons;

struct MoFile {
    immutable(void)[] data;
}

Nullable!MoFile mo;
///////////////////////////////

$ dmd test.d
/snap/dmd/102/bin/../import/phobos/std/format.d(3217): Error: static assert:
"immutable(void)[] must be an InputRange"
/snap/dmd/102/bin/../import/phobos/std/format.d(1875):        instantiated from
here: formatValueImpl!(Appender!string, immutable(void)[], char)
/snap/dmd/102/bin/../import/phobos/std/format.d(3749):        instantiated from
here: formatValue!(Appender!string, immutable(void)[], char)
/snap/dmd/102/bin/../import/phobos/std/format.d(4451):        instantiated from
here: formatElement!(Appender!string, immutable(void)[], char)
/snap/dmd/102/bin/../import/phobos/std/format.d(1875):        ... (2
instantiations, -v to show) ...
/snap/dmd/102/bin/../import/phobos/std/typecons.d(2791):        instantiated
from here: toString!(Appender!string)
test.d(7):        instantiated from here: Nullable!(MoFile)

--
May 20, 2020
https://issues.dlang.org/show_bug.cgi?id=20848

--- Comment #2 from Victor Porton <porton@narod.ru> ---
The error is here (format.d from phobos):

private void formatValueImpl(Writer, T, Char)(auto ref Writer w, T obj, scope
const ref FormatSpec!Char f)
if (is(DynamicArrayTypeOf!T) && !is(StringTypeOf!T) && !is(T == enum) &&
!hasToString!(T, Char))
{
    static if (is(const(ArrayTypeOf!T) == const(void[])))
    {
        formatValueImpl(w, cast(const ubyte[]) obj, f);
    }
    else static if (!isInputRange!T)
    {
        alias U = Unqual!(ArrayTypeOf!T);
        static assert(isInputRange!U, U.stringof ~ " must be an InputRange");
        U val = obj;
        formatValueImpl(w, val, f);
    }
    else
    {
        formatRange(w, obj, f);
    }
}

In the above code the type immutable(void)[] is forgotten to be considered.
Somebody, please fix it.

--
May 20, 2020
https://issues.dlang.org/show_bug.cgi?id=20848

Victor Porton <porton@narod.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Bug in Nullable             |Bug in formatValueImpl

--
July 13, 2020
https://issues.dlang.org/show_bug.cgi?id=20848

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@quickfur created dlang/phobos pull request #7556 "Fix issue 20848: format should work with immutable(void)[]" fixing this issue:

- Fix issue 20848: format should work with immutable(void)[]

  The bug is that if `T == immutable(void)[]`, then `const(T)` does not
  collapse to `const(void[])`, but is actually `const(immutable(void)[])`.
  So a strict type equality check will fail.

  However, `const(T)` *is* implicitly convertible to `const(void[])`,
  which serves our purpose just as well. So just use that check instead.

https://github.com/dlang/phobos/pull/7556

--
January 28, 2021
https://issues.dlang.org/show_bug.cgi?id=20848

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/phobos pull request #7556 "Fix issue 20848: format should work with immutable(void)[]" was merged into master:

- 7cc61dda2ce197c44fbb6d505f31d81e654f5054 by H. S. Teoh:
  Fix issue 20848: format should work with immutable(void)[]

  The bug is that if `T == immutable(void)[]`, then `const(T)` does not
  collapse to `const(void[])`, but is actually `const(immutable(void)[])`.
  So a strict type equality check will fail.

  However, `const(T)` *is* implicitly convertible to `const(void[])`,
  which serves our purpose just as well. So just use that check instead.

https://github.com/dlang/phobos/pull/7556

--