Skip to content

Commit

Permalink
Merge pull request #359 from Basile-z/dcd-600
Browse files Browse the repository at this point in the history
prevent invalid scope when parsing bodies containing erroneous decls
merged-on-behalf-of: Basile-z <Basile-z@users.noreply.github.com>
  • Loading branch information
dlang-bot authored May 11, 2019
2 parents 61519b6 + f773808 commit ec2089d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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.

0 comments on commit ec2089d

Please sign in to comment.