Mercurial > projects > ddmd
diff dmd/TemplateDeclaration.d @ 179:cd48cb899aee
Updated to dmd2.040
author | korDen |
---|---|
date | Sun, 17 Oct 2010 20:56:07 +0400 |
parents | e3afd1303184 |
children | b0d41ff5e0df |
line wrap: on
line diff
--- a/dmd/TemplateDeclaration.d Sun Oct 17 07:42:00 2010 +0400 +++ b/dmd/TemplateDeclaration.d Sun Oct 17 20:56:07 2010 +0400 @@ -183,7 +183,8 @@ override void semantic(Scope sc) { version (LOG) { - printf("TemplateDeclaration.semantic(this = %p, id = '%s')\n", this, ident.toChars()); + writef("TemplateDeclaration.semantic(this = %p, id = '%s')\n", this, ident.toChars()); + writef("sc.stc = %llx\n", sc.stc); } if (semanticRun) return; // semantic() already run @@ -703,7 +704,9 @@ printf("\tfarg[%d] is %s, type is %s\n", i, e.toChars(), e.type.toChars()); } printf("fd = %s\n", fd.toChars()); - printf("fd.type = %p\n", fd.type); + printf("fd.type = %s\n", fd.type.toChars()); + if (ethis) + printf("ethis.type = %s\n", ethis.type.toChars()); } assert(cast(size_t)cast(void*)scope_ > 0x10000); @@ -875,9 +878,9 @@ L2: version (DMDV2) { - // Match 'ethis' to any TemplateThisParameter's if (ethis) { + // Match 'ethis' to any TemplateThisParameter's for (size_t i = 0; i < parameters.dim; i++) { auto tp2 = parameters[i]; @@ -894,6 +897,35 @@ match = m; // pick worst match } } + + // Match attributes of ethis against attributes of fd + if (fd.type) + { + Type tthis = ethis.type; + MOD mod = fd.type.mod; + StorageClass stc = scope_.stc; + if (stc & (STCshared | STCsynchronized)) + mod |= MODshared; + if (stc & STCimmutable) + mod |= MODimmutable; + if (stc & STCconst) + mod |= MODconst; + if (stc & STCwild) + mod |= MODwild; + // Fix mod + if (mod & MODimmutable) + mod = MODimmutable; + if (mod & MODconst) + mod &= ~STCwild; + if (tthis.mod != mod) + { + if (!MODimplicitConv(tthis.mod, mod)) + goto Lnomatch; + if (MATCHconst < match) + match = MATCHconst; + } + } + } } @@ -1050,8 +1082,8 @@ */ for (size_t i = nargsi; i < dedargs.dim; i++) { - auto tp2 = parameters[i]; - //printf("tp2[%d] = %s\n", i, tp2.ident.toChars()); + auto tparam = parameters[i]; + //printf("tparam[%d] = %s\n", i, tparam.ident.toChars()); /* For T:T*, the dedargs is the T*, dedtypes is the T * But for function templates, we really need them to match */ @@ -1064,30 +1096,39 @@ { if (oded) { - if (tp2.specialization()) + if (tparam.specialization()) { /* The specialization can work as long as afterwards * the oded == oarg */ Declaration sparam; dedargs[i] = oded; - MATCH m2 = tp2.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam, 0); + MATCH m2 = tparam.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam, 0); //printf("m2 = %d\n", m2); if (!m2) goto Lnomatch; if (m2 < match) match = m2; // pick worst match if (dedtypes[i] !is oded) - error("specialization not allowed for deduced parameter %s", tp2.ident.toChars()); + error("specialization not allowed for deduced parameter %s", tparam.ident.toChars()); } } else { - oded = tp2.defaultArg(loc, paramscope); if (!oded) - goto Lnomatch; + { + if (tp && // if tuple parameter and + fptupindex < 0 && // tuple parameter was not in function parameter list and + nargsi == dedargs.dim - 1) // we're one argument short (i.e. no tuple argument) + { + // make tuple argument an empty tuple + oded = new Tuple(); + } + else + goto Lnomatch; + } } - declareParameter(paramscope, tp2, oded); + declareParameter(paramscope, tparam, oded); dedargs[i] = oded; } } @@ -1169,6 +1210,7 @@ printf("\t%s %s\n", arg.type.toChars(), arg.toChars()); //printf("\tty = %d\n", arg.type.ty); } + printf("stc = %llx\n", scope_.stc); } for (TemplateDeclaration td = this; td; td = td.overnext)