Skip to content
Merged
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
62 changes: 56 additions & 6 deletions src/dscanner/analysis/base.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module dscanner.analysis.base;

import dparse.ast;
import dparse.lexer : IdType, str, Token, tok;
import dparse.lexer : IdType, str, tok, Token;
import dscanner.analysis.nolint;
import dsymbol.scope_ : Scope;
import std.array;
Expand Down Expand Up @@ -639,12 +639,13 @@ public:
{
// case and default statements always open new scopes and close
// previous case scopes
bool close = switchStack.length && switchStack[$ - 1].inCase;
bool b = switchStack[$ - 1].inCase;
switchStack[$ - 1].inCase = true;
bool wasInCase = switchStack.length && switchStack[$ - 1].inCase;
if (switchStack.length)
switchStack[$ - 1].inCase = true;
scope (exit)
switchStack[$ - 1].inCase = b;
if (close)
if (switchStack.length)
switchStack[$ - 1].inCase = wasInCase;
if (wasInCase)
{
popScope();
pushScope();
Expand Down Expand Up @@ -897,3 +898,52 @@ unittest
auto isOldScope = void;
});
}

// test previous segfault
unittest
{
import dparse.lexer : getTokensForParser, LexerConfig, StringCache;
import dparse.parser : parseModule;
import dparse.rollback_allocator : RollbackAllocator;

StringCache cache = StringCache(4096);
LexerConfig config;
RollbackAllocator rba;
auto tokens = getTokensForParser(q{
module derp;

void main(string[] args)
{
foreach
switch (x)
{
case 1:
if (y) {
continue;
}
break;
default:
break;
}
}
}, config, &cache);
auto m = parseModule(tokens, "stdin", &rba);

class TestScopedAnalyzer : ScopedBaseAnalyzer
{
this()
{
super(BaseAnalyzerArguments("stdin"));
}

override protected void pushScope()
{
}

override protected void popScope()
{
}
}

new TestScopedAnalyzer().visit(m);
}
Loading