Skip to content

Commit 196528d

Browse files
0-v-0WebFreak001
authored andcommitted
Fix #526, support int*[0].init
1 parent 6b0a901 commit 196528d

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

src/dparse/ast.d

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4141,6 +4141,30 @@ unittest // issue #398: Support extern(C++, <string expressions...>)
41414141
checkText(ns[2], `"baz"`);
41424142
}
41434143

4144+
unittest // issue #526
4145+
{
4146+
import dparse.formatter, dparse.lexer, dparse.parser, dparse.rollback_allocator;
4147+
string src = q{enum E : int*[0] { a = int*[0].init }};
4148+
final class Test : ASTVisitor
4149+
{
4150+
}
4151+
RollbackAllocator ra;
4152+
auto cf = LexerConfig("", StringBehavior.source);
4153+
auto ca = StringCache(16);
4154+
Module m = ParserConfig(getTokensForParser(src, cf, &ca), "", &ra).parseModule();
4155+
auto t = new Test;
4156+
t.visit(m);
4157+
assert(m.declarations.length == 1);
4158+
auto ed = m.declarations[0].enumDeclaration;
4159+
assert(ed);
4160+
auto type = ed.type;
4161+
auto app = appender!string();
4162+
auto formatter = new Formatter!(typeof(app))(app);
4163+
formatter.format(type);
4164+
assert(app[] == "int*[0]");
4165+
assert(ed.type.typeSuffixes.length == 2);
4166+
}
4167+
41444168
unittest // Differentiate between no and empty DDOC comments, e.g. for DDOC unittests
41454169
{
41464170
import dparse.lexer, dparse.parser, dparse.rollback_allocator;

src/dparse/parser.d

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5923,18 +5923,31 @@ class Parser
59235923
break;
59245924
}
59255925
foreach (B; BasicTypes) { case B: }
5926-
node.basicType = advance();
5926+
{
5927+
auto bookmark = setBookmark();
5928+
auto c = allocator.setCheckpoint();
5929+
if (auto t = parseType())
5930+
{
5931+
abandonBookmark(bookmark);
5932+
node.type = t;
5933+
}
5934+
else
5935+
{
5936+
allocator.rollback(c);
5937+
goToBookmark(bookmark);
5938+
node.basicType = advance();
5939+
}
59275940
if (currentIs(tok!"."))
59285941
{
59295942
advance();
5930-
const t = expect(tok!"identifier");
5931-
if (t !is null)
5932-
node.primary = *t;
5943+
if (const ident = expect(tok!"identifier"))
5944+
node.primary = *ident;
59335945
}
59345946
else if (currentIs(tok!"("))
59355947
mixin(parseNodeQ!(`node.arguments`, `Arguments`));
59365948
else goto default;
5937-
break;
5949+
}
5950+
break;
59385951
case tok!"function":
59395952
case tok!"delegate":
59405953
case tok!"{":

test/pass_files/issue0526.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum E : int*[0] { a = int*[0].init }

0 commit comments

Comments
 (0)