Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent invalid scope when parsing bodies containing erroneous decls #359

Merged
merged 1 commit into from May 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions src/dparse/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -2371,13 +2371,26 @@ class Parser
if (!declarationsAndStatements.put(parseDeclarationOrStatement()))
{
allocator.rollback(c);

// detect the pattern ".}" for DCD. This is what happens when
// located at the end of a well delimited body/scope and requesting
// completion. This is also a case where it's sure sure that
// there's no ambiguity, even if it happens during a lookup:
// it's not a decl, it's not a statement, it's an error.
if (currentIs(tok!"}") && index > 0 && previous == tok!".")
break;

if (suppressMessages > 0)
return null;

// better for DCD, if the end of the block is reached then
// go back, allowing the following declarations to be in
// the right scope, instead of the block we were in.
if (index > 0 && previous == tok!"}")
{
index -= 1;
break;
}
}
}
ownArray(node.declarationsAndStatements, declarationsAndStatements);
Expand Down
15 changes: 15 additions & 0 deletions test/fail_files/dcd_tricks.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct A { int a; }
struct B { int b; }

B node;

void foo(A node)
{
void bar(B node)
{
node.
}
node.
}

node.