www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12357] New: Untyped string variable fails silently. No compiler warning given.

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

           Summary: Untyped string variable fails silently. No compiler
                    warning given.
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dev nomad.so


--- Comment #0 from Gary Willoughby <dev nomad.so> 2014-03-13 06:56:55 PDT ---
Rather nasty bug that silently fails. Linux DMD64 D Compiler v2.065

import std.stdio;
import std.array;
import std.conv;
import std.digest.crc;
import std.random;

class Foo
{
    public string generateHash()
    {
        // The following variable is untyped
        // yet no compiler error is thrown.
        text = Random(unpredictableSeed).front.to!(string);

        // text is null here.
        return hexDigest!(CRC32)(text).array.to!(string);
    }
}

void main(string[] args)
{
    auto foo = new Foo();

    writefln("%s", foo.generateHash());
}

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2014-03-13
07:10:58 PDT ---
As noted in the forums, this is related to property enforcement. It should be
marked as a dupe of whatever the bug report was that has Kenji's pull request.

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


Adam D. Ruppe <destructionator gmail.com> changed:

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


--- Comment #2 from Adam D. Ruppe <destructionator gmail.com> 2014-03-13
07:14:08 PDT ---
I'm not sure it all is to blame on the whole property thing...

1) The text function in the "setter" call returned a value that was unused. I
think text in this case is a pure function, so that's a noop and potentially
could be an error for that reason.

2) In the second case, it calls text with zero arguments, which i don't think
ever makes sense. Perhaps we could change the signature to add an if(T.length)
constraint to text.



But yeah, the reason this is allowed at all is the loose property setter and
optional parens features rather than a compiler bug.

-- 
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=12357



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2014-03-13
07:18:51 PDT ---
(In reply to comment #2)
 I'm not sure it all is to blame on the whole property thing...
 
 1) The text function in the "setter" call returned a value that was unused. I
 think text in this case is a pure function, so that's a noop and potentially
 could be an error for that reason.

Yeah.
 2) In the second case, it calls text with zero arguments, which i don't think
 ever makes sense. Perhaps we could change the signature to add an if(T.length)
 constraint to text.

I didn't even catch the second call. We could fix this right now. Although, would any generic code break? E.g.: void doStuff(T...)(T t) { call(t[0]); writeln(text(t[1..$])); // would end up failing if T.length is 1 } I fear the 'if(T.length)' would have to be used at the call site too. I'm not sure if this is a problem. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 13 2014