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

VS2017 crashes when parsing C# Span code #25485

Closed
yaakov-h opened this issue Mar 15, 2018 · 5 comments
Closed

VS2017 crashes when parsing C# Span code #25485

yaakov-h opened this issue Mar 15, 2018 · 5 comments

Comments

@yaakov-h
Copy link
Member

Version Used:

Microsoft Visual Studio Enterprise 2017
Version 15.6.2

Steps to Reproduce:

  1. Create a new Class Library (Classic Desktop) project
  2. Add a NuGet package reference to System.Memory (4.5.x pre-release)
  3. Modify Class1.cs to contain the following:
using System;

namespace ClassLibrary1
{
    public class Class1
    {
        public void Foo(Thing[] first, Thing[] second)
        {
            var x = first[0];
        }
    }

    public struct Thing { }
}
  1. On line 7, change the first Thing[] to Span<Thing>[]

Expected Behavior:

error CS0611: Array elements cannot be of type 'Span<Thing>'

Actual Behavior:

Entire Visual Studio IDE locks up and eventually crashes.

Exception:

System.InvalidOperationException
  HResult=0x80131509
  Message=Unexpected value 'ArrayAccess expression of System.Span<ClassLibrary1.Thing> type' of type 'System.String'
  Source=Microsoft.CodeAnalysis.CSharp
  StackTrace:
   at Microsoft.CodeAnalysis.CSharp.Binder.GetValEscape(BoundExpression expr, UInt32 scopeOfTheContainingExpression)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindVariableDeclaration(SourceLocalSymbol localSymbol, LocalDeclarationKind kind, Boolean isVar, VariableDeclaratorSyntax declarator, TypeSyntax typeSyntax, TypeSymbol declTypeOpt, AliasSymbol aliasOpt, DiagnosticBag diagnostics, CSharpSyntaxNode associatedSyntaxNode)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindDeclarationStatementParts(LocalDeclarationStatementSyntax node, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.IncrementalBinder.BindStatement(StatementSyntax 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.SyntaxTreeSemanticModel.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, ArrayBuilder`1 result, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.Classification.Classifiers.NameSyntaxClassifier.AddClassifications(SyntaxNode syntax, SemanticModel semanticModel, ArrayBuilder`1 result, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.ClassifyNode(SyntaxNode syntax)
   at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.ProcessNodes()
   at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.Worker.Classify(Workspace workspace, SemanticModel semanticModel, TextSpan textSpan, ArrayBuilder`1 list, Func`2 getNodeClassifiers, Func`2 getTokenClassifiers, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Classification.AbstractSyntaxClassificationService.<AddSemanticClassificationsAsync>d__5.MoveNext()
@svick
Copy link
Contributor

svick commented Mar 15, 2018

This seems to be very similar to #25398.

@yaakov-h
Copy link
Member Author

Same exception, same function, fairly different stack trace.

Hopefully there aren't too many different ways to trigger the same bug...

@jcouv
Copy link
Member

jcouv commented Mar 15, 2018

Tagging @VSadov

@jcouv jcouv added this to the 15.7 milestone Mar 15, 2018
@svick
Copy link
Contributor

svick commented Mar 15, 2018

@yaakov-h

Same exception, same function, fairly different stack trace.

Hopefully there aren't too many different ways to trigger the same bug...

The exception happens when a switch encounters expression it doesn't know how to deal with:

default:
throw ExceptionUtilities.UnexpectedValue($"{expr.Kind} expression of {expr.Type} type");

My guess is that the fix is going to be to add cases for all remaining expression kinds and that should fix all instances of this bug.

@OmarTawfik
Copy link
Contributor

I believe @VSadov fixed this in #25819
I'll add a test and close the issue.

@OmarTawfik OmarTawfik added the 4 - In Review A fix for the issue is submitted for review. label Mar 31, 2018
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Dec 18, 2018
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants