Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/dparse/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -4141,6 +4141,30 @@ unittest // issue #398: Support extern(C++, <string expressions...>)
checkText(ns[2], `"baz"`);
}

unittest // issue #526
{
import dparse.formatter, dparse.lexer, dparse.parser, dparse.rollback_allocator;
string src = q{enum E : int*[0] { a = int*[0].init }};
final class Test : ASTVisitor
{
}
RollbackAllocator ra;
auto cf = LexerConfig("", StringBehavior.source);
auto ca = StringCache(16);
Module m = ParserConfig(getTokensForParser(src, cf, &ca), "", &ra).parseModule();
auto t = new Test;
t.visit(m);
assert(m.declarations.length == 1);
auto ed = m.declarations[0].enumDeclaration;
assert(ed);
auto type = ed.type;
auto app = appender!string();
auto formatter = new Formatter!(typeof(app))(app);
formatter.format(type);
assert(app[] == "int*[0]");
assert(ed.type.typeSuffixes.length == 2);
}

unittest // Differentiate between no and empty DDOC comments, e.g. for DDOC unittests
{
import dparse.lexer, dparse.parser, dparse.rollback_allocator;
Expand Down
23 changes: 18 additions & 5 deletions src/dparse/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -5923,18 +5923,31 @@ class Parser
break;
}
foreach (B; BasicTypes) { case B: }
node.basicType = advance();
{
auto bookmark = setBookmark();
auto c = allocator.setCheckpoint();
if (auto t = parseType())
Copy link
Copy Markdown
Member

@WebFreak001 WebFreak001 Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition always returns true (must be Type -> Type2 -> BuiltinType at this point due to the current token being one of BasicTypes and then the parseType does not require any further things)

Also removes the need for bookmark/checkpoint

Additionally for backwards compatibility add a getter function in ast.d in PrimaryExpression, which returns type?.type2?.builtinType ?? IdType.init

{
abandonBookmark(bookmark);
node.type = t;
}
else
{
allocator.rollback(c);
goToBookmark(bookmark);
node.basicType = advance();
}
if (currentIs(tok!"."))
{
advance();
const t = expect(tok!"identifier");
if (t !is null)
node.primary = *t;
if (const ident = expect(tok!"identifier"))
node.primary = *ident;
}
else if (currentIs(tok!"("))
mixin(parseNodeQ!(`node.arguments`, `Arguments`));
else goto default;
break;
}
break;
case tok!"function":
case tok!"delegate":
case tok!"{":
Expand Down
1 change: 1 addition & 0 deletions test/pass_files/issue0526.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum E : int*[0] { a = int*[0].init }
Loading