Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS crashes if xml is pasted in C# editor #16167

Closed
vladima opened this issue Dec 31, 2016 · 3 comments · Fixed by #16467
Closed

VS crashes if xml is pasted in C# editor #16167

vladima opened this issue Dec 31, 2016 · 3 comments · Fixed by #16467
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug New Language Feature - Local Functions Local Functions
Milestone

Comments

@vladima
Copy link
Contributor

vladima commented Dec 31, 2016

Version Used:

Steps to Reproduce:

  1. create new C# console app
  2. paste text below as a body of Main
      <summary>Copies a range of elements from an <see cref="T:System.Array" /> starting at the first element and pastes them into another <see cref="T:System.Array" /> starting at the first element. The length is specified as a 32-bit integer.</summary>
      <param name="sourceArray">The <see cref="T:System.Array" /> that contains the data to copy.</param>
      <param name="destinationArray">The <see cref="T:System.Array" /> that receives the data.</param>
      <param name="length">A 32-bit integer that represents the number of elements to copy.</param>
      <exception cref="T:System.ArgumentNullException">
        <paramref name="sourceArray" /> is null.-or-<paramref name="destinationArray" /> is null.</exception>
      <exception cref="T:System.RankException">
        <paramref name="sourceArray" /> and <paramref name="destinationArray" /> have different ranks.</exception>
      <exception cref="T:System.ArrayTypeMismatchException">
        <paramref name="sourceArray" /> and <paramref name="destinationArray" /> are of incompatible types.</exception>
      <exception cref="T:System.InvalidCastException">At least one element in <paramref name="sourceArray" /> cannot be cast to the type of <paramref name="destinationArray" />.</exception>
      <exception cref="T:System.ArgumentOutOfRangeException">
        <paramref name="length" /> is less than zero.</exception>
      <exception cref="T:System.ArgumentException">
        <paramref name="length" /> is greater than the number of elements in <paramref name="sourceArray" />.-or-<paramref name="length" /> is greater than the number of elements in <paramref name="destinationArray" />.</exception>

Expected Behavior:
Sea of red in the editor.

Actual Behavior:
VS crashes:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Binder.BindDeclarationPattern(DeclarationPatternSyntax node, BoundExpression operand, TypeSymbol operandType, Boolean hasErrors, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindPattern(PatternSyntax node, BoundExpression operand, TypeSymbol operandType, Boolean hasErrors, DiagnosticBag diagnostics, Boolean wasSwitchCase)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindIsPatternExpression(IsPatternExpressionSyntax node, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(ExpressionSyntax node, DiagnosticBag diagnostics, Boolean invoked, Boolean indexed)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(ExpressionSyntax node, DiagnosticBag diagnostics, Boolean invoked, Boolean indexed)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindNamespaceOrTypeOrExpression(ExpressionSyntax node, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.Bind(Binder binder, CSharpSyntaxNode node, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.MethodBodySemanticModel.Bind(Binder binder, CSharpSyntaxNode node, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetBoundNodes(CSharpSyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetLowerBoundNode(CSharpSyntaxNode node)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetBoundNodes(CSharpSyntaxNode node, CSharpSyntaxNode& bindableNode, BoundNode& lowestBoundNode, BoundNode& highestBoundNode, BoundNode& boundParent)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetSymbolInfoWorker(CSharpSyntaxNode node, SymbolInfoOptions options, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetSymbolInfo(ExpressionSyntax expression, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetSymbolInfo(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Classification.Classifiers.NameSyntaxClassifier.ClassifyTypeSyntax(NameSyntax name, SemanticModel semanticModel, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Classification.Classifiers.NameSyntaxClassifier.ClassifyNode(SyntaxNode syntax, SemanticModel semanticModel, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.Worker.ClassifyNode(SyntaxNode syntax)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.Worker.ProcessNodes()
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.Worker.Classify(Workspace workspace, SemanticModel semanticModel, TextSpan textSpan, List`1 list, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.<AddSemanticClassificationsAsync>d__5.MoveNext()
Stack:
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception)
   at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, System.Action`1<System.Exception>)
   at Microsoft.CodeAnalysis.ErrorReporting.FatalError.ReportUnlessCanceled(System.Exception)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService+<AddSemanticClassificationsAsync>d__5.MoveNext()
   at Microsoft.CodeAnalysis.CSharp.Binder.BindDeclarationPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DeclarationPatternSyntax, Microsoft.CodeAnalysis.CSharp.BoundExpression, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol, Boolean, Microsoft.CodeAnalysis.DiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindPattern(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax, Microsoft.CodeAnalysis.CSharp.BoundExpression, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol, Boolean, Microsoft.CodeAnalysis.DiagnosticBag, Boolean)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindIsPatternExpression(Microsoft.CodeAnalysis.CSharp.Syntax.IsPatternExpressionSyntax, Microsoft.CodeAnalysis.DiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.DiagnosticBag, Boolean, Boolean)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.DiagnosticBag, Boolean, Boolean)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindNamespaceOrTypeOrExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.DiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.Bind(Microsoft.CodeAnalysis.CSharp.Binder, Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, Microsoft.CodeAnalysis.DiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.MethodBodySemanticModel.Bind(Microsoft.CodeAnalysis.CSharp.Binder, Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, Microsoft.CodeAnalysis.DiagnosticBag)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetBoundNodes(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetLowerBoundNode(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetBoundNodes(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode ByRef, Microsoft.CodeAnalysis.CSharp.BoundNode ByRef, Microsoft.CodeAnalysis.CSharp.BoundNode ByRef, Microsoft.CodeAnalysis.CSharp.BoundNode ByRef)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetSymbolInfoWorker(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, SymbolInfoOptions, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetSymbolInfo(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetSymbolInfo(Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Classification.Classifiers.NameSyntaxClassifier.ClassifyTypeSyntax(Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax, Microsoft.CodeAnalysis.SemanticModel, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Classification.Classifiers.NameSyntaxClassifier.ClassifyNode(Microsoft.CodeAnalysis.SyntaxNode, Microsoft.CodeAnalysis.SemanticModel, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService+Worker.ClassifyNode(Microsoft.CodeAnalysis.SyntaxNode)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService+Worker.ProcessNodes()
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService+Worker.Classify(Microsoft.CodeAnalysis.Workspace, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.Text.TextSpan, System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Classification.ClassifiedSpan>, System.Func`2<Microsoft.CodeAnalysis.SyntaxNode,System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, System.Func`2<Microsoft.CodeAnalysis.SyntaxToken,System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService+<AddSemanticClassificationsAsync>d__5.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Microsoft.CodeAnalysis.Classification.AbstractClassificationService+<AddSemanticClassificationsAsync>d__5, Microsoft.CodeAnalysis.Workspaces, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<AddSemanticClassificationsAsync>d__5 ByRef)
   at Microsoft.CodeAnalysis.Classification.AbstractClassificationService.AddSemanticClassificationsAsync(Microsoft.CodeAnalysis.Document, Microsoft.CodeAnalysis.Text.TextSpan, System.Func`2<Microsoft.CodeAnalysis.SyntaxNode,System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, System.Func`2<Microsoft.CodeAnalysis.SyntaxToken,System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Classification.Classifiers.ISyntaxClassifier>>, System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Classification.ClassifiedSpan>, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.AbstractEditorClassificationService.AddSemanticClassificationsAsync(Microsoft.CodeAnalysis.Document, Microsoft.CodeAnalysis.Text.TextSpan, System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Classification.ClassifiedSpan>, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities+<ClassifySpansAsync>d__2.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities+<ClassifySpansAsync>d__2, Microsoft.CodeAnalysis.EditorFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<ClassifySpansAsync>d__2 ByRef)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities.ClassifySpansAsync(Microsoft.CodeAnalysis.Editor.Tagging.TaggerContext`1<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>, Microsoft.CodeAnalysis.Editor.DocumentSnapshotSpan, Microsoft.CodeAnalysis.Editor.IEditorClassificationService, Microsoft.CodeAnalysis.Editor.Shared.Utilities.ClassificationTypeMap)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities+<TryClassifyContainingMemberSpan>d__1.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities+<TryClassifyContainingMemberSpan>d__1, Microsoft.CodeAnalysis.EditorFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<TryClassifyContainingMemberSpan>d__1 ByRef)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities.TryClassifyContainingMemberSpan(Microsoft.CodeAnalysis.Editor.Tagging.TaggerContext`1<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>, Microsoft.CodeAnalysis.Editor.DocumentSnapshotSpan, Microsoft.CodeAnalysis.Editor.IEditorClassificationService, Microsoft.CodeAnalysis.Editor.Shared.Utilities.ClassificationTypeMap)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities+<ProduceTagsAsync>d__0.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities+<ProduceTagsAsync>d__0, Microsoft.CodeAnalysis.EditorFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<ProduceTagsAsync>d__0 ByRef)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationUtilities.ProduceTagsAsync(Microsoft.CodeAnalysis.Editor.Tagging.TaggerContext`1<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>, Microsoft.CodeAnalysis.Editor.DocumentSnapshotSpan, Microsoft.CodeAnalysis.Editor.IEditorClassificationService, Microsoft.CodeAnalysis.Editor.Shared.Utilities.ClassificationTypeMap)
   at Microsoft.CodeAnalysis.Editor.Implementation.Classification.SemanticClassificationViewTaggerProvider.ProduceTagsAsync(Microsoft.CodeAnalysis.Editor.Tagging.TaggerContext`1<Microsoft.VisualStudio.Text.Tagging.IClassificationTag>)
   at Microsoft.CodeAnalysis.Editor.Tagging.AbstractAsynchronousTaggerProvider`1+TagSource+<RecomputeTagsAsync>d__83[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Microsoft.CodeAnalysis.Editor.Tagging.AbstractAsynchronousTaggerProvider`1+TagSource+<RecomputeTagsAsync>d__83[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], Microsoft.CodeAnalysis.EditorFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]](<RecomputeTagsAsync>d__83<System.__Canon> ByRef)
   at Microsoft.CodeAnalysis.Editor.Tagging.AbstractAsynchronousTaggerProvider`1+TagSource[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].RecomputeTagsAsync(System.Object, System.Nullable`1<Microsoft.VisualStudio.Text.SnapshotPoint>, System.Nullable`1<Microsoft.CodeAnalysis.Text.TextChangeRange>, System.Collections.Generic.List`1<Microsoft.CodeAnalysis.Editor.DocumentSnapshotSpan>, System.Collections.Immutable.ImmutableDictionary`2<Microsoft.VisualStudio.Text.ITextBuffer,Microsoft.CodeAnalysis.Editor.Shared.Tagging.TagSpanIntervalTree`1<System.__Canon>>, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Tagging.AbstractAsynchronousTaggerProvider`1+TagSource+<>c__DisplayClass74_0[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<RecomputeTagsForeground>b__0(System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.Editor.Shared.Threading.AsynchronousSerialWorkQueue+<>c__DisplayClass11_0.<EnqueueBackgroundTask>b__0(System.Threading.Tasks.Task)
   at System.Threading.Tasks.ContinuationResultTaskFromTask`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.Tasks.Task.ExecutionContextCallback(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
   at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

@CyrusNajmabadi
Copy link
Member

Tagging @gafter @jcouv as this relates to BindDeclarationPattern

@gafter gafter added the Bug label Dec 31, 2016
@gafter gafter self-assigned this Dec 31, 2016
@gafter gafter added this to the 2.0 (RC.3) milestone Dec 31, 2016
@gafter
Copy link
Member

gafter commented Jan 5, 2017

Here is a narrowed-down test case:

        [Fact, WorkItem(16167, "https://github.com/dotnet/roslyn/issues/16167")]
        public void Bug16167Root()
        {
            var text = @"
using System;
using System.Collections.Generic;
using System.Linq;

class C
{
    public static void Main(string[] args)
    {
        void Local1(bool b = args is string[] z1) {}
        void Local2(bool b = M(out int z2)) {}
        void Local3((int, int) ii = ((int a1, int a2) = (1, 2)) {}
    }
    public static M(out int z) z = 1;
}
";
            var compilation = CreateCompilationWithMscorlib45(text);
            var tree = compilation.SyntaxTrees[0];
            var model = compilation.GetSemanticModel(tree);
            foreach (var node in tree.GetRoot().DescendantNodes())
            {
                var _ = model.GetSymbolInfo(node);
            }
        }

@jaredpar
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment