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

Ensure that IOperations nodes within a C# local function are part of … #19906

Merged
merged 2 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Compilers/CSharp/Portable/BoundTree/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,16 +854,18 @@ public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, T

partial class BoundLocalFunctionStatement
{
protected override OperationKind StatementKind => OperationKind.LocalFunctionStatement;
protected override OperationKind StatementKind => OperationKind.None;

protected override ImmutableArray<IOperation> Children => ImmutableArray.Create<IOperation>(this.Body);

public override void Accept(OperationVisitor visitor)
{
visitor.VisitLocalFunctionStatement(this);
visitor.VisitNoneOperation(this);
}

public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, TResult> visitor, TArgument argument)
{
return visitor.VisitLocalFunctionStatement(this, argument);
return visitor.VisitNoneOperation(this, argument);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,5 +850,48 @@ public void Method1(object x)

VerifyOperationTreeAndDiagnosticsForTest<IsPatternExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics);
}

[Fact, WorkItem(19902, "https://github.com/dotnet/roslyn/issues/19902")]
public void ParameterReference_LocalFunctionStatement()
{
string source = @"
using System;
using System.Collections.Generic;

class Class
{
static IEnumerable<T> MyIterator<T>(IEnumerable<T> source, Func<T, bool> predicate)
{
/*<bind>*/IEnumerable<T> Iterator()
{
foreach (var element in source)
if (predicate(element))
yield return element;
}/*</bind>*/

return Iterator();
}
}

";
string expectedOperationTree = @"
IOperation: (OperationKind.None) (Syntax: 'IEnumerable ... }')
Children(1): IBlockStatement (2 statements) (OperationKind.BlockStatement) (Syntax: '{ ... }')
IForEachLoopStatement (Iteration variable: T element) (LoopKind.ForEach) (OperationKind.LoopStatement) (Syntax: 'foreach (va ... rn element;')
Collection: IConversionExpression (ConversionKind.Cast, Implicit) (OperationKind.ConversionExpression, Type: System.Collections.Generic.IEnumerable<T>) (Syntax: 'source')
IParameterReferenceExpression: source (OperationKind.ParameterReferenceExpression, Type: System.Collections.Generic.IEnumerable<T>) (Syntax: 'source')
Body: IIfStatement (OperationKind.IfStatement) (Syntax: 'if (predica ... rn element;')
Condition: IInvocationExpression (virtual System.Boolean System.Func<T, System.Boolean>.Invoke(T arg)) (OperationKind.InvocationExpression, Type: System.Boolean) (Syntax: 'predicate(element)')
Instance Receiver: IParameterReferenceExpression: predicate (OperationKind.ParameterReferenceExpression, Type: System.Func<T, System.Boolean>) (Syntax: 'predicate')
Arguments(1): IArgument (ArgumentKind.Explicit, Matching Parameter: arg) (OperationKind.Argument) (Syntax: 'element')
ILocalReferenceExpression: element (OperationKind.LocalReferenceExpression, Type: T) (Syntax: 'element')
IfTrue: IReturnStatement (OperationKind.YieldReturnStatement) (Syntax: 'yield return element;')
ILocalReferenceExpression: element (OperationKind.LocalReferenceExpression, Type: T) (Syntax: 'element')
YieldBreakStatement (OperationKind.YieldBreakStatement) (Syntax: '{ ... }')
";
var expectedDiagnostics = DiagnosticDescription.None;

VerifyOperationTreeAndDiagnosticsForTest<LocalFunctionStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
}
}
10 changes: 0 additions & 10 deletions src/Compilers/Core/Portable/Operations/OperationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,6 @@ public virtual void VisitInvalidExpression(IInvalidExpression operation)
{
DefaultVisit(operation);
}

public virtual void VisitLocalFunctionStatement(IOperation operation)
{
DefaultVisit(operation);
}
}

/// <summary>
Expand Down Expand Up @@ -789,10 +784,5 @@ public virtual TResult VisitInvalidExpression(IInvalidExpression operation, TArg
{
return DefaultVisit(operation, argument);
}

public virtual TResult VisitLocalFunctionStatement(IOperation operation, TArgument argument)
{
return DefaultVisit(operation, argument);
}
}
}
2 changes: 0 additions & 2 deletions src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,6 @@ virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLabelStatement(Mi
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLambdaExpression(Microsoft.CodeAnalysis.Semantics.ILambdaExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLateBoundMemberReferenceExpression(Microsoft.CodeAnalysis.Semantics.ILateBoundMemberReferenceExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLiteralExpression(Microsoft.CodeAnalysis.Semantics.ILiteralExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLocalFunctionStatement(Microsoft.CodeAnalysis.IOperation operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLocalReferenceExpression(Microsoft.CodeAnalysis.Semantics.ILocalReferenceExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLockStatement(Microsoft.CodeAnalysis.Semantics.ILockStatement operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitMethodBindingExpression(Microsoft.CodeAnalysis.Semantics.IMethodBindingExpression operation) -> void
Expand Down Expand Up @@ -880,7 +879,6 @@ virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.Vi
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLambdaExpression(Microsoft.CodeAnalysis.Semantics.ILambdaExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLateBoundMemberReferenceExpression(Microsoft.CodeAnalysis.Semantics.ILateBoundMemberReferenceExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLiteralExpression(Microsoft.CodeAnalysis.Semantics.ILiteralExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLocalFunctionStatement(Microsoft.CodeAnalysis.IOperation operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLocalReferenceExpression(Microsoft.CodeAnalysis.Semantics.ILocalReferenceExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLockStatement(Microsoft.CodeAnalysis.Semantics.ILockStatement operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitMethodBindingExpression(Microsoft.CodeAnalysis.Semantics.IMethodBindingExpression operation, TArgument argument) -> TResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,12 +1058,6 @@ public override void VisitIfStatement(IIfStatement operation)
Visit(operation.IfFalseStatement, "IfFalse");
}

public override void VisitLocalFunctionStatement(IOperation operation)
{
LogString(nameof(VisitLocalFunctionStatement));
LogCommonPropertiesAndNewLine(operation);
}

private void LogCaseClauseCommon(ICaseClause operation)
{
var kindStr = $"{nameof(CaseKind)}.{operation.CaseKind}";
Expand Down