Skip to content

Commit

Permalink
Addressing blocking feedback while Neal is OOF
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv authored and jcouv committed Dec 10, 2016
1 parent c5e4534 commit 3e0d9db
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics)
throw ExceptionUtilities.UnexpectedValue(_deconstruction.Kind());
}

Debug.Assert((object)this._type != null);
return this._type;
}

Expand Down Expand Up @@ -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);
}
}
}
}
}
7 changes: 7 additions & 0 deletions src/Compilers/CSharp/Portable/Syntax/SyntaxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
13 changes: 3 additions & 10 deletions src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ private static DeclarationExpressionSyntax GetOutVarDeclaration(SyntaxTree tree,
private static IEnumerable<DeclarationExpressionSyntax> GetOutVarDeclarations(SyntaxTree tree, string name)
{
return tree.GetRoot().DescendantNodes().OfType<DeclarationExpressionSyntax>()
.Where(p => IsOutVarDeclaration(p) && p.Identifier().ValueText == name);
.Where(p => p.IsOutVarDeclaration() && p.Identifier().ValueText == name);
}

private static IEnumerable<DiscardDesignationSyntax> GetDiscardDesignations(SyntaxTree tree)
Expand All @@ -800,17 +800,10 @@ private static IEnumerable<IdentifierNameSyntax> GetDiscardIdentifiers(SyntaxTre
return tree.GetRoot().DescendantNodes().OfType<IdentifierNameSyntax>().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<DeclarationExpressionSyntax> GetOutVarDeclarations(SyntaxTree tree)
{
return tree.GetRoot().DescendantNodes().OfType<DeclarationExpressionSyntax>()
.Where(p => IsOutVarDeclaration(p));
.Where(p => p.IsOutVarDeclaration());
}

[Fact]
Expand Down Expand Up @@ -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<DeclarationExpressionSyntax>().Where(e => IsOutVarDeclaration(e)));
Assert.Empty(parent.Ancestors().OfType<DeclarationExpressionSyntax>().Where(e => e.IsOutVarDeclaration()));

if (parent.Kind() == SyntaxKind.VariableDeclarator)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @"
Expand All @@ -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,
Expand Down

0 comments on commit 3e0d9db

Please sign in to comment.