www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11698] New: readf doesn't compile with bool

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11698

           Summary: readf doesn't compile with bool
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: jlquinn optonline.net



---
dmd 2.064.2 on linux x86_64

module bug;
import std.stdio;
void foo() {
  bool b;
  readf("%s", b);
}

/home/jlquinn/dmd2/linux/bin64/dmd -g -c readf.bug.d
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/format.d(3938): Error:
template std.conv.parse does not match any function template declaration.
Candidates are:
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/conv.d(1943):       
std.conv.parse(Target, Source)(ref Source s) if
(isSomeChar!(ElementType!Source) && isIntegral!Target && !is(Target == enum))
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/conv.d(2203):       
std.conv.parse(Target, Source)(ref Source s, uint radix) if
(isSomeChar!(ElementType!Source) && isIntegral!Target && !is(Target == enum))
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/conv.d(2299):       
std.conv.parse(Target, Source)(ref Source s) if (isExactSomeString!Source &&
is(Target == enum))
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/conv.d(2358):       
std.conv.parse(Target, Source)(ref Source p) if (isInputRange!Source &&
isSomeChar!(ElementType!Source) && !is(Source == enum) &&
isFloatingPoint!Target && !is(Target == enum))
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/conv.d(2834):       
std.conv.parse(Target, Source)(ref Source s) if (isExactSomeString!Source &&
staticIndexOf!(Unqual!Target, dchar, Unqual!(ElementEncodingType!Source)) >= 0)
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/format.d(3938):        ...
(7 more, -v to show) ...
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/format.d(3938): Error:
template std.conv.parse(Target, Source)(ref Source s) if
(isSomeChar!(ElementType!Source) && isIntegral!Target && !is(Target == enum))
cannot deduce template function from argument types !(bool)(LockingTextReader)
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/format.d(582): Error:
template instance std.format.unformatValue!(bool, LockingTextReader, char)
error instantiating
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/stdio.d(1005):       
instantiated from here: formattedRead!(LockingTextReader, char, bool*)
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/stdio.d(2130):       
instantiated from here: readf!(bool*)
readf.bug.d(8):        instantiated from here: readf!(bool*)
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/stdio.d(1005): Error:
template instance std.format.formattedRead!(LockingTextReader, char, bool*)
error instantiating
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/stdio.d(2130):       
instantiated from here: readf!(bool*)
readf.bug.d(8):        instantiated from here: readf!(bool*)
/home/jlquinn/dmd2/linux/bin64/../../src/phobos/std/stdio.d(2130): Error:
template instance std.stdio.File.readf!(bool*) error instantiating
readf.bug.d(8):        instantiated from here: readf!(bool*)
readf.bug.d(8): Error: template instance std.stdio.readf!(bool*) error
instantiating

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 06 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11698




---
Tracking this down further, the issue appears to be that formattedRead(range,
"%s", &bool) calls unformatValue!bool(range, formatSpec) which calls
parse!bool(range).

However, parse!bool doesn't seem to accept an input range:

import std.conv;
import std.range;
void foo() {
    string s = "1";
    auto ir = inputRangeObject(s);
    int i = parse!int(ir);    // OK

    string sb = "true";
    auto irb = inputRangeObject(sb);
    bool b2 = parse!bool(irb);   // Error
}


I *think* the problem is that 

Target parse(Target, Source)(ref Source s)
    if (isExactSomeString!Source &&
        is(Unqual!Target == bool)) { ... }

requires a string rather than an input range.  A version of parse!bool that
accepts a range would fix the problem.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11698




---
Something like this?

Target parse(Target, Source)(ref Source s)
    if (isSomeChar!(ElementType!Source) &&
        is(Unqual!Target == bool))
{
  if (skipOver!("std.ascii.toLower(a) == b")(s, "true"))
    return true;
  if (skipOver!("std.ascii.toLower(a) == b")(s, "false"))
    return false;
  throw convError!(Source, Target)(s);
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 07 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11698


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au gmail.co
                   |                            |m



11:53:36 PST ---
https://github.com/D-Programming-Language/phobos/pull/1984

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11698




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/2ae91087e7fda00a9ca29221ad3f45f4ab4a39f8
Fix Issue 11698 - readf doesn't work with bool

https://github.com/D-Programming-Language/phobos/commit/b99ed6cc3d10aa2c82c3228bb25f0bd655bd73d4


Fix Issue 11698 - readf doesn't work with bool

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 13 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11698


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 13 2014