From c5b298202f780ad716792d7f52842d6e783493ec Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 18 Sep 2008 21:14:16 +0100 Subject: [PATCH] Fix parsing problem with array initialisers The D parser has to cope with two types of array: int foo = 10 new byte[foo] and: alias char[] foo new byte[foo] When it parses the new line, it's not ready to resolve the symbol foo, so it assumes the second case and then rewrites it later during the semantic pass if foo turns out to be an expression instead. Turning foo into foo? broke that. --- dmd/parse.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dmd/parse.c b/dmd/parse.c index 667a437..d56438a 100644 --- a/dmd/parse.c +++ b/dmd/parse.c @@ -1769,6 +1769,13 @@ Type *Parser::parseBasicType2(Type *t) //printf("it's an associative array\n"); index = parseBasicType(); index = parseDeclarator(index, NULL); // [ type ] + if (index->ty == Tmaybe && !dltSyntax) + { + // This might be an expression. Remove the + // maybe, so that D can try to resolve it as + // a variable instead. + index = index->next; + } t = new TypeAArray(t, index); check(TOKrbracket); } -- 2.11.4.GIT