[Issue 7375] New: Regression(2.057): Invalid downcast permitted with derived/aliased template classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 27 00:22:41 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7375

           Summary: Regression(2.057): Invalid downcast permitted with
                    derived/aliased template classes
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: cbkbbejeap at mailinator.com


--- Comment #0 from Nick Sabalausky <cbkbbejeap at mailinator.com> 2012-01-27 00:22:38 PST ---
a.d:
----------------
import b;

void main(string[] args)
{
    auto foo = getEleven();
    //auto dummy = cast(Derived!11)foo;
    assert(cast(Derived!22)foo is null);
}

alias DerivedAlias!22 X;
----------------

b.d:
----------------
module b;

Base getEleven()
{
    Base foo = new MoreDerived!11(null);
    return foo;
}

class Base
{
    Base a;
    this(Base a)
    {
        this.a = a;
    }
}

class Derived(int i) : Base
{
    this(Base a)
    {
        super(a);
    }
}

class MoreDerived(int i) : Derived!i
{
    this(Base a)
    {
        super(a);
    }
}

template DerivedAlias(int i)
{
    alias Derived!i DerivedAlias;
}
----------------

On 2.057, the assert fails. (It's fine on 2.056.)

If you uncomment the "dummy" line, the problem goes away (merely creating an
alias for Derived!11 does not work). However, that's *not* a general workaround
because in order to test what the runtime type is, you have to *already* know
*all* the types it might be and attempt to downcast to each of them.

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


More information about the Digitalmars-d-bugs mailing list