Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 29, 2017 Compiler bug? | ||||
---|---|---|---|---|
| ||||
The following code: int guess; readln().formattedRead!"%d"(guess); produces the following compiler error: Error: template std.format.formattedRead cannot deduce function from argument types !("%s")(string, int), candidates are: /usr/include/dmd/phobos/std/format.d(635): std.format.formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) if (isSomeString!(typeof(fmt))) /usr/include/dmd/phobos/std/format.d(644): std.format.formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, auto ref S args) That is odd! I expected this to match: uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) However, the following works!!! int guess; string line = readln(); line.formattedRead!"%d"(guess); This definitely looks like a bug, but I want to confirm first before filing one. |
December 29, 2017 Re: Compiler bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to IM Attachments:
| No it is not a bug, because
uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args)
could not match (there is a ref R r) so in your first example you dont have
lvalue but rvalue
On Fri, Dec 29, 2017 at 8:30 AM, IM via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
> The following code:
>
> int guess;
> readln().formattedRead!"%d"(guess);
>
> produces the following compiler error:
>
> Error: template std.format.formattedRead cannot deduce function from
> argument types !("%s")(string, int), candidates are:
> /usr/include/dmd/phobos/std/format.d(635):
> std.format.formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) if
> (isSomeString!(typeof(fmt)))
> /usr/include/dmd/phobos/std/format.d(644):
> std.format.formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, auto
> ref S args)
>
> That is odd! I expected this to match:
>
> uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args)
>
> However, the following works!!!
>
> int guess;
> string line = readln();
> line.formattedRead!"%d"(guess);
>
>
> This definitely looks like a bug, but I want to confirm first before filing one.
>
>
|
December 29, 2017 Re: Compiler bug? | ||||
---|---|---|---|---|
| ||||
Attachments:
| But maybe you can propose cjange from ref R r to auto ref R r https://dlang.org/spec/template.html#auto-ref-parameters On Fri, Dec 29, 2017 at 8:50 AM, Daniel Kozak <kozzi11@gmail.com> wrote: > No it is not a bug, because > uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) > could not match (there is a ref R r) so in your first example you dont > have lvalue but rvalue > > > On Fri, Dec 29, 2017 at 8:30 AM, IM via Digitalmars-d < digitalmars-d@puremagic.com> wrote: > >> The following code: >> >> int guess; >> readln().formattedRead!"%d"(guess); >> >> produces the following compiler error: >> >> Error: template std.format.formattedRead cannot deduce function from >> argument types !("%s")(string, int), candidates are: >> /usr/include/dmd/phobos/std/format.d(635): >> std.format.formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) if >> (isSomeString!(typeof(fmt))) >> /usr/include/dmd/phobos/std/format.d(644): >> std.format.formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, auto >> ref S args) >> >> That is odd! I expected this to match: >> >> uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) >> >> However, the following works!!! >> >> int guess; >> string line = readln(); >> line.formattedRead!"%d"(guess); >> >> >> This definitely looks like a bug, but I want to confirm first before filing one. >> >> > |
December 29, 2017 Re: Compiler bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On Friday, 29 December 2017 at 07:55:08 UTC, Daniel Kozak wrote: > But maybe you can propose cjange from ref R r to auto ref R r > If this will make it work with both lvalues and rvalues, then yes, this would be a nice fix. No need to force users to cache string line = readln(); first and then use it with formattedRead(). > https://dlang.org/spec/template.html#auto-ref-parameters > > On Fri, Dec 29, 2017 at 8:50 AM, Daniel Kozak <kozzi11@gmail.com> wrote: > >> No it is not a bug, because >> uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) >> could not match (there is a ref R r) so in your first example you dont >> have lvalue but rvalue >> |
December 29, 2017 Re: Compiler bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to IM | On Friday, 29 December 2017 at 08:02:36 UTC, IM wrote: > On Friday, 29 December 2017 at 07:55:08 UTC, Daniel Kozak wrote: >> But maybe you can propose cjange from ref R r to auto ref R r >> > > If this will make it work with both lvalues and rvalues, then yes, this would be a nice fix. No need to force users to cache string line = readln(); first and then use it with formattedRead(). > >> https://dlang.org/spec/template.html#auto-ref-parameters >> >> On Fri, Dec 29, 2017 at 8:50 AM, Daniel Kozak <kozzi11@gmail.com> wrote: >> >>> No it is not a bug, because >>> uint formattedRead(alias fmt, R, S...)(ref R r, auto ref S args) >>> could not match (there is a ref R r) so in your first example you dont >>> have lvalue but rvalue https://github.com/dlang/phobos/pull/5971 |
Copyright © 1999-2021 by the D Language Foundation