Skip to content
Closed
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
26 changes: 15 additions & 11 deletions dsymbol/src/dsymbol/conversion/first.d
Original file line number Diff line number Diff line change
Expand Up @@ -723,20 +723,20 @@ final class FirstPass : ASTVisitor

override void visit(const IfStatement ifs)
{
if (ifs.identifier != tok!"" && ifs.thenStatement)
if (ifs.condition && ifs.condition.identifier != tok!"" && ifs.thenStatement)
{
pushScope(ifs.thenStatement.startLocation, ifs.thenStatement.endLocation);
scope(exit) popScope();

SemanticSymbol* symbol = allocateSemanticSymbol(ifs.identifier.text,
CompletionKind.variableName, symbolFile, ifs.identifier.index);
if (ifs.type !is null)
addTypeToLookups(symbol.typeLookups, ifs.type);
SemanticSymbol* symbol = allocateSemanticSymbol(ifs.condition.identifier.text,
CompletionKind.variableName, symbolFile, ifs.condition.identifier.index);
if (ifs.condition !is null && ifs.condition.type !is null)
addTypeToLookups(symbol.typeLookups, ifs.condition.type);
symbol.parent = currentSymbol;
currentSymbol.addChild(symbol, true);
currentScope.addSymbol(symbol.acSymbol, true);
if (symbol.typeLookups.empty && ifs.expression !is null)
populateInitializer(symbol, ifs.expression, false);
if (symbol.typeLookups.empty && ifs.condition !is null && ifs.condition.expression !is null)
populateInitializer(symbol, ifs.condition.expression, false);
}
ifs.accept(this);
}
Expand Down Expand Up @@ -1091,7 +1091,10 @@ private:
auto lookup = TypeLookupsAllocator.instance.make!TypeLookup(TypeLookupKind.initializer);
scope visitor = new InitializerVisitor(lookup, appendForeach, this);
symbol.typeLookups.insert(lookup);
visitor.visit(initializer);
static if (is(T == typeof(feExpression)))
visitor.dynamicDispatch(initializer);
else
visitor.visit(initializer);
}

SemanticSymbol* allocateSemanticSymbol(string name, CompletionKind kind,
Expand Down Expand Up @@ -1361,6 +1364,7 @@ class InitializerVisitor : ASTVisitor
}

alias visit = ASTVisitor.visit;
alias dynamicDispatch = ASTVisitor.dynamicDispatch;

override void visit(const FunctionLiteralExpression exp)
{
Expand Down Expand Up @@ -1442,7 +1446,7 @@ class InitializerVisitor : ASTVisitor

override void visit(const IndexExpression expr)
{
expr.unaryExpression.accept(this);
dynamicDispatch(expr.unaryExpression);
foreach (index; expr.indexes)
if (index.high is null)
lookup.breadcrumbs.insert(ARRAY_SYMBOL_NAME);
Expand Down Expand Up @@ -1534,10 +1538,10 @@ class InitializerVisitor : ASTVisitor
on = false;
}

override void visit(const ExpressionNode expression)
override void dynamicDispatch(const ExpressionNode expression)
{
on = true;
expression.accept(this);
super.dynamicDispatch(expression);
if (appendForeach)
lookup.breadcrumbs.insert(internString("foreach"));
on = false;
Expand Down
9 changes: 9 additions & 0 deletions dsymbol/src/dsymbol/tests.d
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ unittest
DSymbol* S = pair.symbol.getFirstPartNamed(internString("S"));
DSymbol* b = pair.symbol.getFirstPartNamed(internString("b"));
assert(S);
assert(b);
assert(b.type);
assert(b.type is S);
}
{
Expand All @@ -343,6 +345,8 @@ unittest
DSymbol* S = pair.symbol.getFirstPartNamed(internString("S"));
DSymbol* b = pair.symbol.getFirstPartNamed(internString("b"));
assert(S);
assert(b);
assert(b.type);
assert(b.type is S);
}
{
Expand All @@ -351,6 +355,8 @@ unittest
DSymbol* S = pair.symbol.getFirstPartNamed(internString("S"));
DSymbol* b = pair.symbol.getFirstPartNamed(internString("b"));
assert(S);
assert(b);
assert(b.type);
assert(b.type.type is S);
}
{
Expand All @@ -359,6 +365,8 @@ unittest
DSymbol* S = pair.symbol.getFirstPartNamed(internString("S"));
DSymbol* b = pair.symbol.getFirstPartNamed(internString("b"));
assert(S);
assert(b);
assert(b.type);
assert(b.type.name == ARRAY_SYMBOL_NAME);
assert(b.type.type is S);
}
Expand All @@ -368,6 +376,7 @@ unittest
DSymbol* S = pair.symbol.getFirstPartNamed(internString("S"));
DSymbol* b = pair.symbol.getFirstPartNamed(internString("b"));
assert(S);
assert(b);
assert(b.type is S);
}
}
Expand Down