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

Crach VS2017 craches when insert code with twice use one name out variable #30357

Closed
vsfeedback opened this issue Oct 7, 2018 · 1 comment
Closed
Assignees
Labels
Area-Compilers Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com
Milestone

Comments

@vsfeedback
Copy link

crashtestconsoleapp.zip

class Program
    {
        static void Main(string[] args)
        {
            var int_string = "123";
            // Replace "0" to "int.TryParse(int_string, out var i) ? i : default(int)"
            new TestData(int_string, 0) { Number = int.TryParse(int_string, out var i) ? i : default(int) };
        }

        struct TestData
        {
            public int Number { get; set; }
            public string Str { get; }

            public TestData(string str, int number)
            {
                Str = str;
                Number = number;
            }
        }
    }

This issue has been moved from https://developercommunity.visualstudio.com/content/problem/328269/crach-vs2017-craches-when-insert-code-with-twice-u.html
VSTS ticketId: 677539

These are the original issue comments:
(no comments)
These are the original issue solutions:
(no solutions)

@svick
Copy link
Contributor

svick commented Oct 7, 2018

Here is an even smaller repro:

class C
{
    int Number { get; set; }

    C(int number) { }

    void M(string s) =>
        new C(int.TryParse(s, out var i) ? i : 0) { Number = int.TryParse(s, out var i) ? i : 0 };
}

This code causes a StackOverflowException in a release-mode compiler. In a debug-mode compiler, it triggers this assert (used to "detect infinite recursion in type inference"):

Debug.Assert(concurrentTypeResolutions < 50);

The repeating part of the stack trace is:

>	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceLocalSymbol.Type.get() Line 292	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindNonMethod(Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSyntax node, Microsoft.CodeAnalysis.CSharp.Symbol symbol, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.CSharp.LookupResultKind resultKind, bool indexed, bool isError) Line 1534	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindIdentifier(Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSyntax node, bool invoked, bool indexed, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 1251	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, bool invoked, bool indexed) Line 399	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, bool invoked, bool indexed) Line 329	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindValue(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.CSharp.Binder.BindValueKind valueKind) Line 228	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindConditionalOperator(Microsoft.CodeAnalysis.CSharp.Syntax.ConditionalExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 3590	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, bool invoked, bool indexed) Line 467	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, bool invoked, bool indexed) Line 329	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindValue(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.CSharp.Binder.BindValueKind valueKind) Line 228	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindInitializerExpressionOrValue(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax syntax, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol type, Microsoft.CodeAnalysis.SyntaxNode typeSyntax, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 3866	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindObjectInitializerMemberAssignment(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax memberInitializer, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol initializerType, Microsoft.CodeAnalysis.CSharp.Binder objectInitializerMemberBinder, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.CSharp.BoundImplicitReceiver implicitReceiver) Line 3955	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindObjectInitializerExpression(Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax initializerSyntax, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol initializerType, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, Microsoft.CodeAnalysis.CSharp.BoundImplicitReceiver implicitReceiver) Line 3900	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindInitializerExpression(Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax syntax, Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol type, Microsoft.CodeAnalysis.SyntaxNode typeSyntax, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 3837	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindObjectCreationExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 3560	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, bool invoked, bool indexed) Line 396	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, bool invoked, bool indexed) Line 329	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Binder.BindExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax node, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 324	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceLocalSymbol.LocalSymbolWithEnclosingContext.InferTypeOfVarVariable(Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 762	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceLocalSymbol.GetTypeSymbol() Line 335	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Symbols.SourceLocalSymbol.Type.get() Line 294	C#

@jaredpar jaredpar added this to the 16.0 milestone Oct 8, 2018
@sharwell sharwell added the Developer Community The issue was originally reported on https://developercommunity.visualstudio.com label Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com
Projects
None yet
Development

No branches or pull requests

5 participants