From 3e0d9db709ac74da834ba475e3bfb33e04d1e368 Mon Sep 17 00:00:00 2001 From: jcouv Date: Fri, 9 Dec 2016 15:53:29 -0800 Subject: [PATCH] Addressing blocking feedback while Neal is OOF --- .../Symbols/Source/SourceLocalSymbol.cs | 17 +++++++++++++++++ .../CSharp/Portable/Syntax/SyntaxExtensions.cs | 7 +++++++ .../Test/Semantic/Semantics/OutVarTests.cs | 13 +++---------- .../Indentation/SmartIndenterTests.cs | 5 +++-- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs index ba25263bd6229..1f488088e6baa 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs @@ -673,6 +673,7 @@ protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics) throw ExceptionUtilities.UnexpectedValue(_deconstruction.Kind()); } + Debug.Assert((object)this._type != null); return this._type; } @@ -755,11 +756,27 @@ protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics) if ((object)this._type == null) { + AssertNoOutOrPatternVariable(); SetType(_nodeBinder.CreateErrorType("var")); } return this._type; } + + [Conditional("DEBUG")] + private void AssertNoOutOrPatternVariable() + { + var parent = this._typeSyntax.Parent; + + if (parent?.Kind() == SyntaxKind.DeclarationExpression && ((DeclarationExpressionSyntax)parent).IsOutVarDeclaration()) + { + Debug.Assert(false); + } + else if (parent?.Kind() == SyntaxKind.DeclarationPattern) + { + Debug.Assert(false); + } + } } } } diff --git a/src/Compilers/CSharp/Portable/Syntax/SyntaxExtensions.cs b/src/Compilers/CSharp/Portable/Syntax/SyntaxExtensions.cs index 616600389ec95..4b92c4b2ff624 100644 --- a/src/Compilers/CSharp/Portable/Syntax/SyntaxExtensions.cs +++ b/src/Compilers/CSharp/Portable/Syntax/SyntaxExtensions.cs @@ -376,5 +376,12 @@ internal static CSharpSyntaxNode GetContainingDeconstruction(this ExpressionSynt } } } + + internal static bool IsOutVarDeclaration(this DeclarationExpressionSyntax p) + { + return p.Designation.Kind() == SyntaxKind.SingleVariableDesignation + && p.Parent?.Kind() == SyntaxKind.Argument + && ((ArgumentSyntax)p.Parent).RefOrOutKeyword.Kind() == SyntaxKind.OutKeyword; + } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs index 60f84cc196153..7b4403990f34c 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs @@ -787,7 +787,7 @@ private static DeclarationExpressionSyntax GetOutVarDeclaration(SyntaxTree tree, private static IEnumerable GetOutVarDeclarations(SyntaxTree tree, string name) { return tree.GetRoot().DescendantNodes().OfType() - .Where(p => IsOutVarDeclaration(p) && p.Identifier().ValueText == name); + .Where(p => p.IsOutVarDeclaration() && p.Identifier().ValueText == name); } private static IEnumerable GetDiscardDesignations(SyntaxTree tree) @@ -800,17 +800,10 @@ private static IEnumerable GetDiscardIdentifiers(SyntaxTre return tree.GetRoot().DescendantNodes().OfType().Where(i => i.Identifier.ContextualKind() == SyntaxKind.UnderscoreToken); } - private static bool IsOutVarDeclaration(DeclarationExpressionSyntax p) - { - return p.Designation.Kind() == SyntaxKind.SingleVariableDesignation - && p.Parent.Kind() == SyntaxKind.Argument - && ((ArgumentSyntax)p.Parent).RefOrOutKeyword.Kind() == SyntaxKind.OutKeyword; - } - private static IEnumerable GetOutVarDeclarations(SyntaxTree tree) { return tree.GetRoot().DescendantNodes().OfType() - .Where(p => IsOutVarDeclaration(p)); + .Where(p => p.IsOutVarDeclaration()); } [Fact] @@ -1042,7 +1035,7 @@ private static void VerifyNotAnOutLocal(SemanticModel model, IdentifierNameSynta var local = (SourceLocalSymbol)symbol; var parent = local.IdentifierToken.Parent; - Assert.Empty(parent.Ancestors().OfType().Where(e => IsOutVarDeclaration(e))); + Assert.Empty(parent.Ancestors().OfType().Where(e => e.IsOutVarDeclaration())); if (parent.Kind() == SyntaxKind.VariableDeclarator) { diff --git a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs index a32dd9ad3f72e..ea6ee3770398c 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartIndenterTests.cs @@ -2570,7 +2570,7 @@ await AssertSmartIndentAsync( expectedIndentation: 8); } - [WpfFact(Skip = "test is no longer correct due to language changes"), Trait(Traits.Feature, Traits.Features.SmartIndent)] + [WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/15813"), Trait(Traits.Feature, Traits.Features.SmartIndent)] public async Task DontCreateIndentOperationForBrokenBracketedArgumentList() { var code = @" @@ -2583,7 +2583,8 @@ static void M() } } "; - + // Need to confirm expected behavior after discard/deconstruction parsing changes + // https://github.com/dotnet/roslyn/issues/15813 await AssertSmartIndentAsync( code, indentationLine: 6,