Skip to content

Commit

Permalink
Merge pull request #3717 from 9rnsr/fix13026
Browse files Browse the repository at this point in the history
[REG2.066a] Issue 13026 - object.get cannot be called with [] as "defaultValue" argument
  • Loading branch information
WalterBright authored and 9rnsr committed Jul 7, 2014
1 parent 79a5347 commit a8dd4dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/template.c
Expand Up @@ -4377,8 +4377,14 @@ MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *par
idexp = new IdentifierExp(Loc(), Id::empty);
idexp->type = Type::tbool;
}
CondExp *condexp = new CondExp(Loc(), idexp, ((TypeTypeof *)at)->exp, e);
CondExp *condexp = new CondExp(e->loc, idexp, ((TypeTypeof *)at)->exp, e);
unsigned olderrors = global.startGagging();
Expression *ec = condexp->semantic(sc);
if (global.endGagging(olderrors))
{
result = MATCHnomatch;
return true;
}
if (ec == condexp)
{
((TypeTypeof *)at)->exp = condexp;
Expand Down Expand Up @@ -4466,6 +4472,10 @@ MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *par
e->type->nextOf()->sarrayOf(e->elements->dim)->accept(this);
return;
}

if (deduceExpType(e)) // Bugzilla 13026
return;

visit((Expression *)e);
}

Expand Down
9 changes: 6 additions & 3 deletions test/runnable/template9.d
Expand Up @@ -3338,14 +3338,17 @@ void test12290()
static assert(is(typeof(func3a("str1" , "str2"d)) == dstring));
static assert(is(typeof(func3b("str1"d, "str2" )) == dstring));

inout(V) get12220(K, V)(inout(V[K]) aa, K key, lazy V defaultValue) { return V.init; }
inout(V) get(K, V)(inout(V[K]) aa, K key, lazy V defaultValue) { return V.init; }

short[short] hash12220;
short res12220 = get12220(hash12220, 1, 1);
short res12220 = get(hash12220, 1, 1);

void get12221(K, V)(inout(V[K]) aa, K key, lazy V defaultValue) {}
short[short] hash12221;
enum Key12221 : short { a }
get(hash12221, Key12221.a, Key12221.a);

int[][string] mapping13026;
int[] v = get(mapping13026, "test", []);
}

/******************************************/
Expand Down

0 comments on commit a8dd4dc

Please sign in to comment.