Skip to content

Commit

Permalink
Merge pull request #3658 from 9rnsr/fix11421
Browse files Browse the repository at this point in the history
Issue 11421 - Dynamic array of associative array literal type inference
  • Loading branch information
WalterBright committed Jun 15, 2014
2 parents 0a7a8b3 + e8f96dc commit d4ea0c0
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 205 deletions.
31 changes: 2 additions & 29 deletions src/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,41 +990,14 @@ void VarDeclaration::semantic(Scope *sc)
if (needctfe) sc = sc->startCTFE();

//printf("inferring type for %s with init %s\n", toChars(), init->toChars());
ArrayInitializer *ai = init->isArrayInitializer();
if (ai)
{
Expression *e;
if (ai->isAssociativeArray())
e = ai->toAssocArrayLiteral();
else
e = init->toExpression();
if (!e)
{
error("cannot infer type from initializer");
e = new ErrorExp();
}
init = new ExpInitializer(e->loc, e);
type = init->inferType(sc);
if (type->ty == Tsarray)
type = type->nextOf()->arrayOf();
}
else
{
type = init->inferType(sc);
}
init = init->inferType(sc);
type = init->toExpression()->type;

if (needctfe) sc = sc->endCTFE();
// type = type->semantic(loc, sc);

inuse--;
inferred = 1;

if (init->isArrayInitializer() && type->toBasetype()->ty == Tsarray)
{
// Prefer array literals to give a T[] type rather than a T[dim]
type = type->toBasetype()->nextOf()->arrayOf();
}

/* This is a kludge to support the existing syntax for RAII
* declarations.
*/
Expand Down

0 comments on commit d4ea0c0

Please sign in to comment.