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

Changeset 786

Show
Ignore:
Timestamp:
12/06/10 08:19:47 (14 years ago)
Author:
walter
Message:

bugzilla 5094 No implicit conversion with 'alias property this'

Files:

Legend:

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

    r769 r786  
    70907090    } 
    70917091    return TRUE; 
    70927092} 
    70937093 
    70947094int TypeStruct::hasPointers() 
    70957095{ 
    70967096    // Probably should cache this information in sym rather than recompute 
    70977097    StructDeclaration *s = sym; 
    70987098 
    70997099    sym->size(0);               // give error for forward references 
    71007100    for (size_t i = 0; i < s->fields.dim; i++) 
    71017101    { 
    71027102        Dsymbol *sm = (Dsymbol *)s->fields.data[i]; 
    71037103        Declaration *d = sm->isDeclaration(); 
    71047104        if (d->storage_class & STCref || d->hasPointers()) 
    71057105            return TRUE; 
    71067106    } 
    71077107    return FALSE; 
    71087108} 
    71097109 
     7110static MATCH aliasthisConvTo(AggregateDeclaration *ad, Type *from, Type *to) 
     7111{ 
     7112    assert(ad->aliasthis); 
     7113    Declaration *d = ad->aliasthis->isDeclaration(); 
     7114    if (d) 
     7115    {   assert(d->type); 
     7116        Type *t = d->type; 
     7117        if (d->isVarDeclaration() && d->needThis()) 
     7118        { 
     7119            t = t->addMod(from->mod); 
     7120        } 
     7121        else if (d->isFuncDeclaration()) 
     7122        { 
     7123            FuncDeclaration *fd = (FuncDeclaration *)d; 
     7124            Expression *ethis = from->defaultInit(0); 
     7125            fd = fd->overloadResolve(0, ethis, NULL); 
     7126            if (fd) 
     7127                t = ((TypeFunction *)fd->type)->next; 
     7128        } 
     7129        return t->implicitConvTo(to); 
     7130    } 
     7131    return MATCHnomatch; 
     7132} 
     7133 
    71107134MATCH TypeStruct::implicitConvTo(Type *to) 
    71117135{   MATCH m; 
    71127136 
    71137137    //printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(), to->toChars()); 
    71147138    if (to->ty == Taarray) 
    71157139    { 
    71167140        /* If there is an error instantiating AssociativeArray!(), it shouldn't 
    71177141         * be reported -- it just means implicit conversion is impossible. 
    71187142         */ 
    71197143        ++global.gag; 
    71207144        int errs = global.errors; 
    71217145        to = ((TypeAArray*)to)->getImpl()->type; 
    71227146        --global.gag; 
    71237147        if (errs != global.errors) 
    71247148        {   global.errors = errs; 
    71257149            return MATCHnomatch; 
    71267150        } 
    71277151    } 
    71287152 
    71297153    if (ty == to->ty && sym == ((TypeStruct *)to)->sym) 
     
    71397163                for (int i = 0; i < sym->fields.dim; i++) 
    71407164                {   Dsymbol *s = (Dsymbol *)sym->fields.data[i]; 
    71417165                    VarDeclaration *v = s->isVarDeclaration(); 
    71427166                    assert(v && v->storage_class & STCfield); 
    71437167 
    71447168                    // 'from' type 
    71457169                    Type *tvf = v->type->addMod(mod); 
    71467170 
    71477171                    // 'to' type 
    71487172                    Type *tv = v->type->castMod(to->mod); 
    71497173 
    71507174                    //printf("\t%s => %s, match = %d\n", v->type->toChars(), tv->toChars(), tvf->implicitConvTo(tv)); 
    71517175                    if (tvf->implicitConvTo(tv) < MATCHconst) 
    71527176                        return MATCHnomatch; 
    71537177                } 
    71547178                m = MATCHconst; 
    71557179            } 
    71567180        } 
    71577181    } 
    71587182    else if (sym->aliasthis) 
    7159     { 
    7160         m = MATCHnomatch; 
    7161         Declaration *d = sym->aliasthis->isDeclaration(); 
    7162         if (d) 
    7163         {   assert(d->type); 
    7164             Type *t = d->type->addMod(mod); 
    7165             m = t->implicitConvTo(to); 
    7166         } 
    7167     } 
     7183        m = aliasthisConvTo(sym, this, to); 
    71687184    else 
    71697185        m = MATCHnomatch;       // no match 
    71707186    return m; 
    71717187} 
    71727188 
    71737189Type *TypeStruct::toHeadMutable() 
    71747190{ 
    71757191    return this; 
    71767192} 
    71777193 
    71787194MATCH TypeStruct::constConv(Type *to) 
    71797195{ 
    71807196    if (equals(to)) 
    71817197        return MATCHexact; 
    71827198    if (ty == to->ty && sym == ((TypeStruct *)to)->sym && 
    71837199        MODimplicitConv(mod, to->mod)) 
    71847200        return MATCHconst; 
    71857201    return MATCHnomatch; 
    71867202} 
    71877203 
     
    75637579    //printf("TypeClass::implicitConvTo(to = '%s') %s\n", to->toChars(), toChars()); 
    75647580    MATCH m = constConv(to); 
    75657581    if (m != MATCHnomatch) 
    75667582        return m; 
    75677583 
    75687584    ClassDeclaration *cdto = to->isClassHandle(); 
    75697585    if (cdto && cdto->isBaseOf(sym, NULL)) 
    75707586    {   //printf("'to' is base\n"); 
    75717587        return MATCHconvert; 
    75727588    } 
    75737589 
    75747590    if (global.params.Dversion == 1) 
    75757591    { 
    75767592        // Allow conversion to (void *) 
    75777593        if (to->ty == Tpointer && ((TypePointer *)to)->next->ty == Tvoid) 
    75787594            return MATCHconvert; 
    75797595    } 
    75807596 
    75817597    m = MATCHnomatch; 
    75827598    if (sym->aliasthis) 
    7583     { 
    7584         Declaration *d = sym->aliasthis->isDeclaration(); 
    7585         if (d) 
    7586         {   assert(d->type); 
    7587             Type *t = d->type->addMod(mod); 
    7588             m = t->implicitConvTo(to); 
    7589         } 
    7590     } 
     7599        m = aliasthisConvTo(sym, this, to); 
    75917600 
    75927601    return m; 
    75937602} 
    75947603 
    75957604MATCH TypeClass::constConv(Type *to) 
    75967605{ 
    75977606    if (equals(to)) 
    75987607        return MATCHexact; 
    75997608    if (ty == to->ty && sym == ((TypeClass *)to)->sym && 
    76007609        MODimplicitConv(mod, to->mod)) 
    76017610        return MATCHconst; 
    76027611    return MATCHnomatch; 
    76037612} 
    76047613 
    76057614Type *TypeClass::toHeadMutable() 
    76067615{ 
    76077616    return this; 
    76087617} 
    76097618 
    76107619Expression *TypeClass::defaultInit(Loc loc)