dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.05k stars 4.03k forks source link

Visual Studio crashes when writing name of a property from a lambda passed to an attribute. #44771

Open vsfeedback opened 4 years ago

vsfeedback commented 4 years ago

This issue has been moved from a ticket on Developer Community.


Visual Studio Community 2019 freezes and eventually crashes when I type the name of a field or property in a lambda that is passed as a parameter to an attribute.

[Bruh(() =>
    {
            Text // This will crash Visual Studio
            Bool // This will also crash Visual Studio
            return null; // This is not necessary to cause the bug.
    })]
public class Class : HierarchyObject
{
    [Any]
    public void Method()
    {
    }

public string Text { get; }
    public bool Bool { get; }
}

internal sealed class BruhAttribute : Attribute
{
    public BruhAttribute(Func<string> funcy)
    {
    }
}

internal sealed class AnyAttribute : Attribute
{
    public AnyAttribute()
    {
    }
}

To recreate the bug you need:

Then simply write the name of one of the properties in the lambda and Visual Studio will crash.


Original Comments

Visual Studio Feedback System on 4/8/2020, 00:27 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Visual Studio Feedback System on 5/14/2020, 07:38 PM:

I have detected that for the last 35 days, this issue didn't have much product team activity and a very small amount of new votes or comments. Based on this, its severity, and affected area, it’s my experience that this issue is very unlikely to be fixed.


Original Solutions

(no solutions)

RikkiGibson commented 4 years ago

This is also present in Visual Studio 15.9.23.

RikkiGibson commented 4 years ago

It's a stack overflow with the following call cycle:

Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.UnboundLambdaState.ReallyBind(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol delegateType) Line 557  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.UnboundLambdaState.Bind(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol delegateType) Line 494    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.UnboundLambda.Bind(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol delegateType) Line 375 C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.ConversionsBase.IsAnonymousFunctionCompatibleWithDelegate(Microsoft.CodeAnalysis.CSharp.UnboundLambda anonymousFunction, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol type) Line 1297   C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.ConversionsBase.HasAnonymousFunctionConversion(Microsoft.CodeAnalysis.CSharp.BoundExpression source, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol destination) Line 1374    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.ConversionsBase.ClassifyImplicitBuiltInConversionFromExpression(Microsoft.CodeAnalysis.CSharp.BoundExpression sourceExpression, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol source, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol destination, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 898   C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.ConversionsBase.ClassifyImplicitConversionFromExpression(Microsoft.CodeAnalysis.CSharp.BoundExpression sourceExpression, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol destination, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 91    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.OverloadResolution.IsApplicable(Microsoft.CodeAnalysis.CSharp.Symbol candidate, Microsoft.CodeAnalysis.CSharp.OverloadResolution.EffectiveParameters parameters, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments arguments, System.Collections.Immutable.ImmutableArray<int> argsToParameters, bool isVararg, bool hasAnyRefOmittedArgument, bool ignoreOpenTypes, bool completeResults, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 3385    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.OverloadResolution.IsConstructorApplicableInNormalForm(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol constructor, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments arguments, bool completeResults, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 548  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.OverloadResolution.AddConstructorToCandidateSet(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol constructor, Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder<Microsoft.CodeAnalysis.CSharp.MemberResolutionResult<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol>> results, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments arguments, bool completeResults, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 502    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.OverloadResolution.PerformObjectCreationOverloadResolution(Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder<Microsoft.CodeAnalysis.CSharp.MemberResolutionResult<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol>> results, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol> constructors, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments arguments, bool completeResults, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 1186  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.OverloadResolution.ObjectCreationOverloadResolution(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol> constructors, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments arguments, Microsoft.CodeAnalysis.CSharp.OverloadResolutionResult<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol> result, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 101  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.TryPerformConstructorOverloadResolution(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol typeContainingConstructors, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments analyzedArguments, string errorName, Microsoft.CodeAnalysis.Location errorLocation, bool suppressResultDiagnostics, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, out Microsoft.CodeAnalysis.CSharp.MemberResolutionResult<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol> memberResolutionResult, out System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol> candidateConstructors, bool allowProtectedConstructorsOfBaseType) Line 5428 C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindAttributeConstructor(Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax node, Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol attributeType, Microsoft.CodeAnalysis.CSharp.AnalyzedArguments boundConstructorArguments, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, ref Microsoft.CodeAnalysis.CSharp.LookupResultKind resultKind, bool suppressErrors, ref System.Collections.Immutable.ImmutableArray<int> argsToParamsOpt, ref bool expanded, ref System.Collections.Generic.HashSet<Microsoft.CodeAnalysis.DiagnosticInfo> useSiteDiagnostics) Line 536    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindAttributeCore(Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax node, Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol attributeType, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 157 C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.GetAttributes(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Binder> binders, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax> attributesToBind, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol> boundAttributeTypes, Microsoft.CodeAnalysis.CSharp.Symbols.CSharpAttributeData[] attributesBuilder, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 78    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbol.LoadAndValidateAttributes(Roslyn.Utilities.OneOrMany<Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax>> attributesSyntaxLists, ref Microsoft.CodeAnalysis.CustomAttributesBag<Microsoft.CodeAnalysis.CSharp.Symbols.CSharpAttributeData> lazyCustomAttributesBag, Microsoft.CodeAnalysis.CSharp.Symbols.AttributeLocation symbolPart, bool earlyDecodingOnly, Microsoft.CodeAnalysis.CSharp.Binder binderOpt, System.Func<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax, bool> attributeMatchesOpt) Line 320    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamedTypeSymbol.GetAttributesBag() Line 645   C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamedTypeSymbol.GetDecodedWellKnownAttributeData() Line 668   C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceNamedTypeSymbol.Layout.get() Line 1149    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.FieldSymbolWithAttributesAndModifiers.PostDecodeWellKnownAttributes(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Symbols.CSharpAttributeData> boundAttributes, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax> allAttributeSyntaxNodes, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.CSharp.Symbols.AttributeLocation symbolPart, Microsoft.CodeAnalysis.WellKnownAttributeData decodedData) Line 323    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbol.LoadAndValidateAttributes(Roslyn.Utilities.OneOrMany<Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax>> attributesSyntaxLists, ref Microsoft.CodeAnalysis.CustomAttributesBag<Microsoft.CodeAnalysis.CSharp.Symbols.CSharpAttributeData> lazyCustomAttributesBag, Microsoft.CodeAnalysis.CSharp.Symbols.AttributeLocation symbolPart, bool earlyDecodingOnly, Microsoft.CodeAnalysis.CSharp.Binder binderOpt, System.Func<Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax, bool> attributeMatchesOpt) Line 348    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.FieldSymbolWithAttributesAndModifiers.GetAttributesBag() Line 87    C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.FieldSymbolWithAttributesAndModifiers.GetAttributes() Line 70   C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourcePropertySymbol.GetAttributesBag() Line 1213   C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourcePropertySymbol.GetAttributes() Line 1226  C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.LazyObsoleteDiagnosticInfo.GetResolvedInfo() Line 36    C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.DiagnosticWithInfo.Severity.get() Line 78 C#
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.DiagnosticBag.ToReadOnlyCore<Microsoft.CodeAnalysis.Diagnostic>(System.Collections.Concurrent.ConcurrentQueue<Microsoft.CodeAnalysis.Diagnostic> oldBag) Line 207 C#
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.UnboundLambdaState.ReallyBind(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol delegateType) Line 653  C