Thread overview
[Issue 5365] New: Regression (2.051) alias this causes segfault
Dec 23, 2010
Max Samukha
Dec 23, 2010
Max Samukha
[Issue 5365] Regression (2.051) implicit conversions via alias this are broken
Dec 23, 2010
Max Samukha
Dec 27, 2010
Walter Bright
Dec 27, 2010
Max Samukha
December 23, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5365

           Summary: Regression (2.051) alias this causes segfault
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: samukha@voliacable.com


--- Comment #0 from Max Samukha <samukha@voliacable.com> 2010-12-23 02:19:35 PST ---
The following compiles and runs correctly with dmd 2.050, but segfaults with dmd 2.051

interface IFactory
{
    void foo();
}

class A
{
    protected static class Factory : IFactory
    {
        void foo()
        {
        }
    }

    this()
    {
        _factory = createFactory();
    }

    protected IFactory createFactory()
    {
        return new Factory;
    }

    private IFactory _factory;
    @property final IFactory factory()
    {
        return _factory;
    }

    alias factory this;
}

void main()
{

    IFactory f = new A;
    f.foo(); // segfault
}

Critical for QtD.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 23, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5365


bearophile_hugs@eml.cc changed:

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


--- Comment #1 from bearophile_hugs@eml.cc 2010-12-23 02:44:22 PST ---
It works with DMD 2.051 if I replace this line of the main():
IFactory f = new A;

With:
A f = new A;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 23, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5365



--- Comment #2 from Max Samukha <samukha@voliacable.com> 2010-12-23 03:51:52 PST ---
(In reply to comment #1)
> It works with DMD 2.051 if I replace this line of the main():
> IFactory f = new A;
> 
> With:
> A f = new A;

We still need the implicit cast to work correctly. For example, we cannot pass an A to a function taking an IFactory:

void bar(IFactory f)
{
    f.foo(); // segfault
}

auto a = new A;
bar(a);

Here is a simplified test-case:

class B
{
}

class A
{

    B _b;

    this()
    {
        _b = new B;
    }

    B b()
    {
        return _b;
    }

    alias b this;
}

void main()
{

    auto a = new A;
    B b = a; // b is null
    assert(a._b is b); // fails
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 23, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5365



--- Comment #3 from Max Samukha <samukha@voliacable.com> 2010-12-23 05:26:06 PST ---
Changed subject to something arguably more relevant.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5365


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2010-12-26 18:32:51 PST ---
This was broken by the fix for 5094. The fix for 5094 was good, it just exposed another problem that needed fixing.

http://www.dsource.org/projects/dmd/changeset/818

QtD is an important project for D; please consider trying out the beta compilers as they come out to head off regresssions in the future.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5365



--- Comment #5 from Max Samukha <samukha@voliacable.com> 2010-12-27 04:04:15 PST ---
(In reply to comment #4)
> This was broken by the fix for 5094. The fix for 5094 was good, it just exposed another problem that needed fixing.
> 
> http://www.dsource.org/projects/dmd/changeset/818

This fixes the issue. Thanks!
There is yet another issue that prevents us from implementing multiple
inheritance in a satisfactory way
http://d.puremagic.com/issues/show_bug.cgi?id=5380

> 
> QtD is an important project for D; please consider trying out the beta compilers as they come out to head off regresssions in the future.

We usually do but not this particular version.

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