www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10064] New: opDollar+final interface function results in a wrong code

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

           Summary: opDollar+final interface function results in a wrong
                    code
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-05-11
05:15:14 MSD ---
This module unittest fails when module is in a project but runs fine as a singe
file so one have to look at the generated instructions to see the bug:
---
struct S
{
    size_t[5] arr;

     property size_t opDollar() // line 5
    { return 0; }

    int opIndex(size_t index)
    { return 0; }
}

interface I
{
    final S getS()
    { return S(); }
}

class C: I
{
    this(in size_t[])
    { }
}

unittest
{
    auto i = cast(I) new C([0]);
    i.getS()[$]; // Causes `null this` at line 5
}
---

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


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|opDollar+final interface    |opDollar called on garbage
                   |function results in a wrong |
                   |code                        |


--- Comment #1 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-06-13
15:28:03 MSD ---
I was incorrect about the issue source. `opDollar` is just called on a garbage:
---
struct S
{
    int x = 3;

     disable this();

    this(int)
    { x = 7; }

    int opSlice(size_t, size_t)
    { return 0; }

     property size_t opDollar()
    {
        assert(x == 7 || x == 3); // fails
        assert(x == 7);
        return 0;
    }
}

void main()
{
    auto x = S(0)[0 .. $];
}
---

As a result e.g. this will fail too:
---
import std.range;

void main()
{
    auto x = zip([1])[$ - 1];
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10064


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

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


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2013-07-10 02:58:03 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2331

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10064



--- Comment #3 from github-bugzilla puremagic.com 2013-07-11 15:32:44 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c426980fd31433c0bbc182a1f9cc9476fe625278
fix Issue 10064 - opDollar called on garbage

https://github.com/D-Programming-Language/dmd/commit/33ce37d6495aad7a3d6644392cf47e1af9d9d493
Merge pull request #2331 from 9rnsr/fix10064

Issue 10064 - opDollar called on garbage

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10064


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: -------
Jul 11 2013