www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7348] New: to!string(null) matches more than one template declaration

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

           Summary: to!string(null) matches more than one template
                    declaration
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: trivial
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: alienballance gmail.com



09:56:28 PST ---
import std.conv;
void main()
{
    to!string(null);
}

/usr/include/d/std/conv.d(237): Error: template std.conv.toImpl(T,S) if
(isImplicitlyConvertible!(S,T)) toImpl(T,S) if (isImplicitlyConvertible!(S,T))
matches more than one template declaration,
/usr/include/d/std/conv.d(245):toImpl(T,S) if (isImplicitlyConvertible!(S,T))
and /usr/include/d/std/conv.d(924):toImpl(T,S) if (is(S : Object) &&
isSomeString!(T))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PST ---
While I can see wanting this to work, I'm not sure how it could. What type is
null? Is it string? A wstring? An int[]? An Object? If so, is it an Object or a
class derived from Object? Etc.

And if what you want is a null string, then just assign null to the string.

What are you trying to do here?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




11:58:31 PST ---
[quote]What are you trying to do here?[/quote]

void test(A)(A param)
{
    writeln("A(",text(param),") called");
}

void main() {
    test(null);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




PST ---
Yeah. That doesn't really make sense. null could be anything that's null. And
what type that is completely changes how text is instantiated. If you cast null
to the type that you want, then it'll work. But null is its own type. You can't
really do anything with null on its own like that. It needs be a null
_something_, not just null.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com



PDT ---
Should we close ?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc




 Should we close ?
Don't close unless it's really unfixable in some way. Maybe "void*" is an acceptable textual output for this. --------------------- Related: import std.stdio; void main() { writeln(null); } DMD 2.059 shows: ...\dmd2\src\phobos\std\stdio.d(1562): Error: undefined identifier 'length' ...\dmd2\src\phobos\std\stdio.d(1562): Error: undefined identifier 'ptr', did you mean 'template tr(C1,C2,C3,C4 = immutable(char))'? test.d(3): Error: template instance std.stdio.writeln!(typeof(null)) error instantiating -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




PDT ---
 Don't close unless it's really unfixable in some way.
Seriously, this doesn't make any sense. It's always possible to break the language with stupid examples like this. This is a waste of time and resources. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow gmail.com



16:01:56 PDT ---
I think this bug is valid. text(null) should be equal to "null".

I don't see how this falls under "breaking the language". The OP posted a
plausible use case (logging the calls to a templated function), so calling this
"stupid" is a bit over the line.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348


Kenji Hara <k.hara.pg gmail.com> changed:

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



Now to!string(null) returns cast(string)null.
Because null is implicitly convertible to string.

Unit-test only:
https://github.com/D-Programming-Language/phobos/pull/575

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 12 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




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

https://github.com/D-Programming-Language/phobos/commit/2e3d877f769abcf6ea0a9c6a31902b8cbd02ba75
fix Issue 7348 - to!string(null) matches more than one template declaration

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




Now this code:

import std.conv, std.stdio;
void main() {
    writeln(">", to!string(null), "<");
}


Prints:

<
But I expect something similar to:
null<
------------------------- This code: import std.stdio; void main() { writeln(null); } gives: ...\dmd2\src\phobos\std\stdio.d(1562): Error: undefined identifier 'length' ...\dmd2\src\phobos\std\stdio.d(1562): Error: undefined identifier 'ptr', did you mean 'template tr(C1,C2,C3,C4 = immutable(char))'? test.d(3): Error: template instance std.stdio.writeln!(typeof(null)) error instantiating -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




---

[snip]

OK. I found a good reason why we should select "null" as representation of null
literal instead of "".

Now,, to!string(something) is forwarded to formatValue(w, something, fmtspec).
If we select "" (empty string) as the representation, "" should be able to
*unformat* as null lietral. But, 0 length input matches everywhere.
Then we would be able to unformat null value every time.

string input = "";
typeof(null) nullvalue;
formattedRead(input, "%s", &nullvalue);  // read null value from empty input
formattedRead(input, "%s", &nullvalue);  // ditto
formattedRead(input, "%s", &nullvalue);  // ditto
// can repeat infinitely...

This is obviously strange.

Then we should select a representation for null value which has one or more
length string.
So "null" is the best representation for the typeof(null) in D.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




20:47:58 PDT ---
I agree. I think this behavior is also more useful to the use case in OP's
example (logging).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




---
to!string(null) should be equal to "null":
https://github.com/D-Programming-Language/phobos/pull/599

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348




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

https://github.com/D-Programming-Language/phobos/commit/f5ccd7fdab3272e892f4685bab9cbf9e81eda0bd
Retry to fix Issue 7348 - Format and unformat typeof(null) objects properly

We should represent null literal as "null" instead of "" in formatting, because
unformatting requires one or more length string representation of the object.

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


Issue 7348 & 8040 - null literal should be formatted as "null"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7348


Kenji Hara <k.hara.pg gmail.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2012