Skip to content

Commit

Permalink
Fix crash in resolver when trying to resolve the warning-id Primitive…
Browse files Browse the repository at this point in the history
…Expression within PreprocessorWarningDirective.
  • Loading branch information
dgrunwald committed Aug 2, 2013
1 parent 995988e commit b57806f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,12 @@ CSharpResolver GetPreviouslyScannedContext(AstNode node, out AstNode parent)
parent = node;
CSharpResolver storedResolver;
while (!resolverBeforeDict.TryGetValue(parent, out storedResolver)) {
parent = parent.Parent;
if (parent == null)
AstNode tmp = parent.Parent;
if (tmp == null)
throw new InvalidOperationException("Could not find a resolver state for any parent of the specified node. Are you trying to resolve a node that is not a descendant of the CSharpAstResolver's root node?");
if (tmp.NodeType == NodeType.Whitespace)
return resolver; // special case: resolve expression within preprocessor directive
parent = tmp;
}
return storedResolver;
}
Expand Down
4 changes: 3 additions & 1 deletion ICSharpCode.NRefactory.ConsistencyCheck/ResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public virtual void Validate(CSharpAstResolver resolver, SyntaxTree syntaxTree)
{
foreach (AstNode node in syntaxTree.DescendantsAndSelf.Except(resolvedNodes.Keys)) {
if (!CSharpAstResolver.IsUnresolvableNode(node)) {
Console.WriteLine("Forgot to resolve " + node);
if (!node.Ancestors.Any(a => a is PreProcessorDirective)) {
Console.WriteLine("Forgot to resolve " + node);
}
}
}
foreach (var pair in resolvedNodes) {
Expand Down

0 comments on commit b57806f

Please sign in to comment.