Changeset 811

Show
Ignore:
Timestamp:
12/22/10 04:01:22 (1 year ago)
Author:
walter
Message:

better fix for the recursive template constraint issue

Files:

Legend:

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

    r737 r811  
    9393#endif 
    9494    ; 
    95     version = "v2.051"; 
     95    version = "v2.052"; 
    9696    global.structalign = 8; 
    9797 
  • trunk/src/template.c

    r810 r811  
    13161316         * Recursive attempts are regarded as a constraint failure. 
    13171317         */ 
    1318         /* Previous should also store the scope, as instantiations along a different scope branch 
    1319          * should not conflict 
    1320          */ 
    13211318        int nmatches = 0; 
    13221319        for (Previous *p = previous; p; p = p->prev) 
     
    13241321            if (arrayObjectMatch(p->dedargs, dedargs, this, sc)) 
    13251322            { 
    1326                 //printf("recursive, no match %p %s\n", this, this->toChars()); 
    1327                 nmatches++; 
     1323                //printf("recursive, no match p->sc=%p %p %s\n", p->sc, this, this->toChars()); 
     1324                /* It must be a subscope of p->sc, other scope chains are not recursive 
     1325                 * instantiations. 
     1326                 */ 
     1327                for (Scope *scx = sc; scx; scx = scx->enclosing) 
     1328                { 
     1329                    if (scx == p->sc) 
     1330                        goto Lnomatch; 
     1331                } 
    13281332            } 
    13291333            /* BUG: should also check for ref param differences 
    13301334             */ 
    13311335        } 
    1332         /* Look for 2 matches at least, because sometimes semantic3() gets run causing what appears to 
    1333          * be recursion but isn't. 
    1334          * Template A's constraint instantiates B, B's semantic3() run includes something that has A in its constraint. 
    1335          * Perhaps a better solution is to always defer semantic3() rather than doing it eagerly. The risk 
    1336          * with that is what if semantic3() fails, but our constraint "succeeded"? 
    1337          */ 
    1338         if (nmatches >= 2) 
    1339             goto Lnomatch; 
    13401336 
    13411337        Previous pr; 
    13421338        pr.prev = previous; 
     1339        pr.sc = paramscope; 
    13431340        pr.dedargs = dedargs; 
    13441341        previous = ≺                 // add this to threaded list 
     
    37203717void TemplateInstance::semantic(Scope *sc, Expressions *fargs) 
    37213718{ 
    3722     //printf("TemplateInstance::semantic('%s', this=%p, gag = %d)\n", toChars(), this, global.gag); 
     3719    //printf("TemplateInstance::semantic('%s', this=%p, gag = %d, sc = %p)\n", toChars(), this, global.gag, sc); 
    37233720    if (global.errors && name != Id::AssociativeArray) 
    37243721    { 
  • trunk/src/template.h

    r809 r811  
    6767    struct Previous 
    6868    {   Previous *prev; 
     69        Scope *sc; 
    6970        Objects *dedargs; 
    7071    };