Thread overview
[Issue 7826] New: [D2 Beta] Cannot use getHash in toHash without a warning
Apr 05, 2012
Nick Sabalausky
Apr 06, 2012
Nick Sabalausky
Apr 06, 2012
Don
Apr 06, 2012
Jonathan M Davis
Apr 07, 2012
Walter Bright
April 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7826

           Summary: [D2 Beta] Cannot use getHash in toHash without a
                    warning
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: cbkbbejeap@mailinator.com


--- Comment #0 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2012-04-05 02:25:46 PDT ---
This code works in 2.058, even with warnings enabled:

------------------------
struct Foo
{
    string str;

    const hash_t toHash()
    {
        return typeid(string).getHash(&str);
    }
}
------------------------

But in the 2.059 beta:

>dmd -c -w test.d
test.d(5): Warning: toHash() must be declared as extern (D) uint toHash() const
pure nothrow @safe, not const uint()

However, if the warning is is fixed, it *still* doesn't work:

------------------------
struct Foo
{
    string str;

    const pure nothrow @safe hash_t toHash()
    {
        return typeid(string).getHash(&str);
    }
}
------------------------

testToHash.d(7): Error: pure function 'toHash' cannot call impure function
'getHash'
testToHash.d(7): Error: & D12TypeInfo_Aya6__initZ.getHash is not nothrow
testToHash.d(5): Error: function testToHash.Foo.toHash 'toHash' is nothrow yet
may throw

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7826



--- Comment #1 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2012-04-05 17:11:31 PDT ---
I don't know what the correct solution is supposed to be, but in any case it should be possible to use getHash in toHash with warnings enabled.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7826


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-04-06 00:35:06 PDT ---
Clearly if toHash() is required to be pure, getHash() must also be.
But I think it is unreasonable for the compiler to demand that toHash() be
pure, especially at the present time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7826


Jonathan M Davis <jmdavisProg@gmx.com> changed:

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


--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-04-06 00:49:29 PDT ---
I believe that tohash is among the functions which were decided must be @safe const pure nothrow on classes. So, in that case, I would expect it to be required (though not until Object is appropriately const-correct and whatnot). But I don't see why @safe, const, pure, or nothrow should be required for structs, since no inheritance is involved. With classes, with have to pick what we want and use that for everything (possibly with some overloads which don't have quite the same list of attributes), but structs don't have the same requirements/restrictions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7826



--- Comment #4 from github-bugzilla@puremagic.com 2012-04-06 17:10:03 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c324826ab425da4d2896b2d7abd97ebffcc0231b fix Issue 7826 - [D2 Beta] Cannot use getHash in toHash without a warning

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7826


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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