Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 818

Show
Ignore:
Timestamp:
12/27/10 02:31:18 (14 years ago)
Author:
walter
Message:

bugzilla 5365 Regression (2.051) implicit conversions via alias this are broken

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cast.c

    r774 r818  
    805805            return toDelegate(sc, tf->nextOf()); 
    806806        } 
    807807#endif 
    808808        else 
    809809        { 
    810810            if (typeb->ty == Tstruct) 
    811811            {   TypeStruct *ts = (TypeStruct *)typeb; 
    812812                if (!(tb->ty == Tstruct && ts->sym == ((TypeStruct *)tb)->sym) && 
    813813                    ts->sym->aliasthis) 
    814814                {   /* Forward the cast to our alias this member, rewrite to: 
    815815                     *   cast(to)e1.aliasthis 
    816816                     */ 
    817817                    Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident); 
    818818                    Expression *e = new CastExp(loc, e1, tb); 
    819819                    e = e->semantic(sc); 
    820820                    return e; 
    821821                } 
    822822            } 
    823823            else if (typeb->ty == Tclass) 
    824824            {   TypeClass *ts = (TypeClass *)typeb; 
    825                 if (tb->ty != Tclass && 
    826                     ts->sym->aliasthis) 
    827                 {   /* Forward the cast to our alias this member, rewrite to: 
     825                if (ts->sym->aliasthis) 
     826                { 
     827                    if (tb->ty == Tclass) 
     828                    { 
     829                        ClassDeclaration *cdfrom = typeb->isClassHandle(); 
     830                        ClassDeclaration *cdto   = tb->isClassHandle(); 
     831                        int offset; 
     832                        if (cdto->isBaseOf(cdfrom, &offset)) 
     833                             goto L1; 
     834                    } 
     835                    /* Forward the cast to our alias this member, rewrite to: 
    828836                     *   cast(to)e1.aliasthis 
    829837                     */ 
    830838                    Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident); 
    831839                    Expression *e = new CastExp(loc, e1, tb); 
    832840                    e = e->semantic(sc); 
    833841                    return e; 
    834842                } 
     843             L1: ; 
    835844            } 
    836845            e = new CastExp(loc, e, tb); 
    837846        } 
    838847    } 
    839848    else 
    840849    { 
    841850        e = e->copy();  // because of COW for assignment to e->type 
    842851    } 
    843852    assert(e != this); 
    844853    e->type = t; 
    845854    //printf("Returning: %s\n", e->toChars()); 
    846855    return e; 
    847856} 
    848857 
    849858 
    850859Expression *RealExp::castTo(Scope *sc, Type *t) 
    851860{   Expression *e = this; 
    852861    if (type != t) 
    853862    { 
    854863        if ((type->isreal() && t->isreal()) || 
  • trunk/src/mtype.c

    r812 r818  
    71117111    return FALSE; 
    71127112} 
    71137113 
    71147114static MATCH aliasthisConvTo(AggregateDeclaration *ad, Type *from, Type *to) 
    71157115{ 
    71167116    assert(ad->aliasthis); 
    71177117    Declaration *d = ad->aliasthis->isDeclaration(); 
    71187118    if (d) 
    71197119    {   assert(d->type); 
    71207120        Type *t = d->type; 
    71217121        if (d->isVarDeclaration() && d->needThis()) 
    71227122        { 
    71237123            t = t->addMod(from->mod); 
    71247124        } 
    71257125        else if (d->isFuncDeclaration()) 
    71267126        { 
    71277127            FuncDeclaration *fd = (FuncDeclaration *)d; 
    71287128            Expression *ethis = from->defaultInit(0); 
    71297129            fd = fd->overloadResolve(0, ethis, NULL); 
    71307130            if (fd) 
     7131            { 
    71317132                t = ((TypeFunction *)fd->type)->next; 
    7132         } 
    7133         return t->implicitConvTo(to); 
     7133            } 
     7134        } 
     7135        MATCH m = t->implicitConvTo(to); 
     7136        return m; 
    71347137    } 
    71357138    return MATCHnomatch; 
    71367139} 
    71377140 
    71387141MATCH TypeStruct::implicitConvTo(Type *to) 
    71397142{   MATCH m; 
    71407143 
    71417144    //printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(), to->toChars()); 
    71427145    if (to->ty == Taarray) 
    71437146    { 
    71447147        /* If there is an error instantiating AssociativeArray!(), it shouldn't 
    71457148         * be reported -- it just means implicit conversion is impossible. 
    71467149         */ 
    71477150        ++global.gag; 
    71487151        int errs = global.errors; 
    71497152        to = ((TypeAArray*)to)->getImpl()->type; 
    71507153        --global.gag; 
    71517154        if (errs != global.errors) 
    71527155        { 
    71537156            global.errors = errs;