From 5a6b495a84d580f58571d9b765ada580b3885e12 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Wed, 11 Jan 2017 08:59:10 -0800 Subject: [PATCH] Report more data if spans are out of bounds. --- .../FindSymbols/DeclaredSymbolInfo.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/DeclaredSymbolInfo.cs b/src/Workspaces/Core/Portable/FindSymbols/DeclaredSymbolInfo.cs index 04d82fcd024..240e86ee6ec 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/DeclaredSymbolInfo.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/DeclaredSymbolInfo.cs @@ -1,8 +1,10 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; @@ -111,8 +113,20 @@ public async Task ResolveAsync(Document document, CancellationToken can public ISymbol Resolve(SemanticModel semanticModel, CancellationToken cancellationToken) { var root = semanticModel.SyntaxTree.GetRoot(cancellationToken); - var node = root.FindNode(this.Span); - return semanticModel.GetDeclaredSymbol(node, cancellationToken); + if (root.FullSpan.Contains(this.Span)) + { + var node = root.FindNode(this.Span); + return semanticModel.GetDeclaredSymbol(node, cancellationToken); + } + else + { + var message = +$@"Invalid span in {nameof(DeclaredSymbolInfo)}. +{nameof(this.Span)} = {this.Span} +{nameof(root.FullSpan)} = {root.FullSpan}"; + FatalError.ReportWithoutCrash(new InvalidOperationException(message)); + return null; + } } } -} +} \ No newline at end of file -- GitLab