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

Changeset 232

Show
Ignore:
Timestamp:
11/01/09 05:24:14 (15 years ago)
Author:
walter
Message:

bugzilla 3432

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/expression.c

    r230 r232  
    71087108#if LOGSEMANTIC 
    71097109    printf("CastExp::semantic('%s')\n", toChars()); 
    71107110#endif 
    71117111 
    71127112//static int x; assert(++x < 10); 
    71137113 
    71147114    if (type) 
    71157115    return this; 
    71167116    UnaExp::semantic(sc); 
    71177117    if (e1->type)       // if not a tuple 
    71187118    { 
    71197119    e1 = resolveProperties(sc, e1); 
    71207120    to = to->semantic(loc, sc); 
    71217121 
    71227122    e = op_overload(sc); 
    71237123    if (e) 
    71247124    { 
    71257125        return e->implicitCastTo(sc, to); 
    71267126    } 
    71277127 
     7128    if (e1->op == TOKtemplate) 
     7129    { 
     7130        error("cannot cast template %s to type %s", e1->toChars(), to->toChars()); 
     7131        return new ErrorExp(); 
     7132    } 
     7133 
    71287134    Type *t1b = e1->type->toBasetype(); 
    71297135    Type *tob = to->toBasetype(); 
    71307136    if (tob->ty == Tstruct && 
    71317137        !tob->equals(t1b) && 
    71327138        ((TypeStruct *)to)->sym->search(0, Id::call, 0) 
    71337139       ) 
    71347140    { 
    71357141        /* Look to replace: 
    71367142         *  cast(S)t 
    71377143         * with: 
    71387144         *  S(t) 
    71397145         */ 
    71407146 
    71417147        // Rewrite as to.call(e1) 
    71427148        e = new TypeExp(loc, to); 
    71437149        e = new DotIdExp(loc, e, Id::call); 
    71447150        e = new CallExp(loc, e, e1); 
    71457151        e = e->semantic(sc); 
    71467152        return e; 
    71477153    } 
  • trunk/src/expression.c

    r230 r232  
    74347434    e1 = resolveProperties(sc, e1); 
    74357435 
    74367436    if (!to) 
    74377437    { 
    74387438        /* Handle cast(const) and cast(immutable), etc. 
    74397439         */ 
    74407440        to = e1->type->castMod(mod); 
    74417441    } 
    74427442    else 
    74437443        to = to->semantic(loc, sc); 
    74447444 
    74457445    if (!to->equals(e1->type)) 
    74467446    { 
    74477447        e = op_overload(sc); 
    74487448        if (e) 
    74497449        { 
    74507450        return e->implicitCastTo(sc, to); 
    74517451        } 
    74527452    } 
    74537453 
     7454    if (e1->op == TOKtemplate) 
     7455    { 
     7456        error("cannot cast template %s to type %s", e1->toChars(), to->toChars()); 
     7457        return new ErrorExp(); 
     7458    } 
     7459 
    74547460    Type *t1b = e1->type->toBasetype(); 
    74557461    Type *tob = to->toBasetype(); 
    74567462    if (tob->ty == Tstruct && 
    74577463        !tob->equals(t1b) && 
    74587464        ((TypeStruct *)tob)->sym->search(0, Id::call, 0) 
    74597465       ) 
    74607466    { 
    74617467        /* Look to replace: 
    74627468         *  cast(S)t 
    74637469         * with: 
    74647470         *  S(t) 
    74657471         */ 
    74667472 
    74677473        // Rewrite as to.call(e1) 
    74687474        e = new TypeExp(loc, to); 
    74697475        e = new DotIdExp(loc, e, Id::call); 
    74707476        e = new CallExp(loc, e, e1); 
    74717477        e = e->semantic(sc); 
    74727478        return e; 
    74737479    }