Skip to content

Commit

Permalink
Use F instead of Foo. Because Foo is bad.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Jul 31, 2017
1 parent ee4d972 commit f021ba8
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public void IForEachLoopStatement_ModifyIterationVariable()
string source = @"
class C
{
void Foo(int[] a)
void F(int[] a)
{
/*<bind>*/foreach (int x in a) { x++; }/*</bind>*/
}
Expand All @@ -538,7 +538,7 @@ public void IForEachLoopStatement_Pattern()
string source = @"
class C
{
void Foo(Enumerable e)
void F(Enumerable e)
{
/*<bind>*/foreach (long x in e) { }/*</bind>*/
}
Expand Down Expand Up @@ -571,7 +571,7 @@ public void IForEachLoopStatement_ImplicitlyTypedString()
string source = @"
class C
{
void Foo(string s)
void F(string s)
{
/*<bind>*/foreach (var x in s) { }/*</bind>*/
}
Expand All @@ -592,7 +592,7 @@ public void IForEachLoopStatement_ExplicitlyTypedVar()
string source = @"
class C
{
void Foo(var[] a)
void F(var[] a)
{
/*<bind>*/foreach (var x in a) { }/*</bind>*/
}
Expand All @@ -615,7 +615,7 @@ public void IForEachLoopStatement_DynamicEnumerable()
string source = @"
class C
{
void Foo(dynamic d)
void F(dynamic d)
{
/*<bind>*/foreach (int x in d) { }/*</bind>*/
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,52 +1155,51 @@ class C
{
static void Main(string[] args)
{
/*<bind>*/for (Foo f = new Foo { i = 0, s = ""abc"" }; f.i < 5; f.i = f.i + 1)
/*<bind>*/for (F f = new F { i = 0, s = ""abc"" }; f.i < 5; f.i = f.i + 1)
{
}/*</bind>*/
}
}
public class Foo
public class F
{
public int i;
public string s;
}
";
string expectedOperationTree = @"
IForLoopStatement (LoopKind.For) (OperationKind.LoopStatement) (Syntax: 'for (Foo f ... }')
IForLoopStatement (LoopKind.For) (OperationKind.LoopStatement) (Syntax: 'for (F f = ... }')
Condition: IBinaryOperatorExpression (BinaryOperationKind.IntegerLessThan) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'f.i < 5')
Left: IFieldReferenceExpression: System.Int32 Foo.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'f.i')
Instance Receiver: ILocalReferenceExpression: f (OperationKind.LocalReferenceExpression, Type: Foo) (Syntax: 'f')
Left: IFieldReferenceExpression: System.Int32 F.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'f.i')
Instance Receiver: ILocalReferenceExpression: f (OperationKind.LocalReferenceExpression, Type: F) (Syntax: 'f')
Right: ILiteralExpression (Text: 5) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 5) (Syntax: '5')
Locals: Local_1: Foo f
Locals: Local_1: F f
Before:
IVariableDeclarationStatement (1 declarations) (OperationKind.VariableDeclarationStatement) (Syntax: 'f = new Foo ... s = ""abc"" }')
IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'f = new Foo ... s = ""abc"" }')
Variables: Local_1: Foo f
Initializer: IObjectCreationExpression (Constructor: Foo..ctor()) (OperationKind.ObjectCreationExpression, Type: Foo) (Syntax: 'new Foo { i ... s = ""abc"" }')
IVariableDeclarationStatement (1 declarations) (OperationKind.VariableDeclarationStatement) (Syntax: 'f = new F { ... s = ""abc"" }')
IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'f = new F { ... s = ""abc"" }')
Variables: Local_1: F f
Initializer: IObjectCreationExpression (Constructor: F..ctor()) (OperationKind.ObjectCreationExpression, Type: F) (Syntax: 'new F { i = ... s = ""abc"" }')
Arguments(0)
Initializer: IObjectOrCollectionInitializerExpression (OperationKind.ObjectOrCollectionInitializerExpression, Type: Foo) (Syntax: '{ i = 0, s = ""abc"" }')
Initializer: IObjectOrCollectionInitializerExpression (OperationKind.ObjectOrCollectionInitializerExpression, Type: F) (Syntax: '{ i = 0, s = ""abc"" }')
Initializers(2):
ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Int32) (Syntax: 'i = 0')
Left: IFieldReferenceExpression: System.Int32 Foo.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'i')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: Foo) (Syntax: 'i')
Left: IFieldReferenceExpression: System.Int32 F.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'i')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: F) (Syntax: 'i')
Right: ILiteralExpression (Text: 0) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: '0')
ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.String) (Syntax: 's = ""abc""')
Left: IFieldReferenceExpression: System.String Foo.s (OperationKind.FieldReferenceExpression, Type: System.String) (Syntax: 's')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: Foo) (Syntax: 's')
Left: IFieldReferenceExpression: System.String F.s (OperationKind.FieldReferenceExpression, Type: System.String) (Syntax: 's')
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: F) (Syntax: 's')
Right: ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: ""abc"") (Syntax: '""abc""')
AtLoopBottom:
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'f.i = f.i + 1')
Expression: ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Int32) (Syntax: 'f.i = f.i + 1')
Left: IFieldReferenceExpression: System.Int32 Foo.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'f.i')
Instance Receiver: ILocalReferenceExpression: f (OperationKind.LocalReferenceExpression, Type: Foo) (Syntax: 'f')
Left: IFieldReferenceExpression: System.Int32 F.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'f.i')
Instance Receiver: ILocalReferenceExpression: f (OperationKind.LocalReferenceExpression, Type: F) (Syntax: 'f')
Right: IBinaryOperatorExpression (BinaryOperationKind.IntegerAdd) (OperationKind.BinaryOperatorExpression, Type: System.Int32) (Syntax: 'f.i + 1')
Left: IFieldReferenceExpression: System.Int32 Foo.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'f.i')
Instance Receiver: ILocalReferenceExpression: f (OperationKind.LocalReferenceExpression, Type: Foo) (Syntax: 'f')
Left: IFieldReferenceExpression: System.Int32 F.i (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'f.i')
Instance Receiver: ILocalReferenceExpression: f (OperationKind.LocalReferenceExpression, Type: F) (Syntax: 'f')
Right: ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1')
Body: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: '{ ... }')
";
Body: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: '{ ... }')";
VerifyOperationTreeForTest<ForStatementSyntax>(source, expectedOperationTree);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand Down Expand Up @@ -262,14 +262,14 @@ class C
{
void M()
{
Foo();
F();
int x = 0;
/*<bind>*/void Foo() => x++;/*</bind>*/
/*<bind>*/void F() => x++;/*</bind>*/
}
}
";
string expectedOperationTree = @"
ILocalFunctionStatement (Local Function: void Foo()) (OperationKind.LocalFunctionStatement) (Syntax: 'void Foo() => x++;')
ILocalFunctionStatement (Local Function: void F()) (OperationKind.LocalFunctionStatement) (Syntax: 'void F() => x++;')
IBlockStatement (2 statements) (OperationKind.BlockStatement) (Syntax: '=> x++')
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'x++')
Expression: IIncrementExpression (UnaryOperandKind.IntegerPostfixIncrement) (OperationKind.IncrementExpression, Type: System.Int32) (Syntax: 'x++')
Expand All @@ -279,8 +279,8 @@ void M()
";
var expectedDiagnostics = new DiagnosticDescription[] {
// CS0165: Use of unassigned local variable 'x'
// Foo();
Diagnostic(ErrorCode.ERR_UseDefViolation, "Foo()").WithArguments("x").WithLocation(6, 9)
// F();
Diagnostic(ErrorCode.ERR_UseDefViolation, "F()").WithArguments("x").WithLocation(6, 9)
};

VerifyOperationTreeAndDiagnosticsForTest<LocalFunctionStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
Expand All @@ -295,21 +295,20 @@ class C
void M(int p)
{
int x;
/*<bind>*/void Foo(out int y) => y = p;/*</bind>*/
Foo(out x);
/*<bind>*/void F(out int y) => y = p;/*</bind>*/
F(out x);
}
}
";
string expectedOperationTree = @"
ILocalFunctionStatement (Local Function: void Foo(out System.Int32 y)) (OperationKind.LocalFunctionStatement) (Syntax: 'void Foo(ou ... ) => y = p;')
ILocalFunctionStatement (Local Function: void F(out System.Int32 y)) (OperationKind.LocalFunctionStatement) (Syntax: 'void F(out ... ) => y = p;')
IBlockStatement (2 statements) (OperationKind.BlockStatement) (Syntax: '=> y = p')
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'y = p')
Expression: ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Int32) (Syntax: 'y = p')
Left: IParameterReferenceExpression: y (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'y')
Right: IParameterReferenceExpression: p (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'p')
IReturnStatement (OperationKind.ReturnStatement) (Syntax: '=> y = p')
ReturnedValue: null
";
ReturnedValue: null";
var expectedDiagnostics = DiagnosticDescription.None;

VerifyOperationTreeAndDiagnosticsForTest<LocalFunctionStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
Expand All @@ -323,12 +322,12 @@ class C
{
void M(int p)
{
/*<bind>*/void Foo(out int y) => ;/*</bind>*/
/*<bind>*/void F(out int y) => ;/*</bind>*/
}
}
";
string expectedOperationTree = @"
ILocalFunctionStatement (Local Function: void Foo(out System.Int32 y)) (OperationKind.LocalFunctionStatement, IsInvalid) (Syntax: 'void Foo(out int y) => ;')
ILocalFunctionStatement (Local Function: void F(out System.Int32 y)) (OperationKind.LocalFunctionStatement, IsInvalid) (Syntax: 'void F(out int y) => ;')
IBlockStatement (2 statements) (OperationKind.BlockStatement, IsInvalid) (Syntax: '=> ')
IExpressionStatement (OperationKind.ExpressionStatement, IsInvalid) (Syntax: '')
Expression: IInvalidExpression (OperationKind.InvalidExpression, Type: ?, IsInvalid) (Syntax: '')
Expand All @@ -337,15 +336,15 @@ void M(int p)
ReturnedValue: null
";
var expectedDiagnostics = new DiagnosticDescription[] {
// CS1525: Invalid expression term ';'
// /*<bind>*/void Foo(out int y) => ;/*</bind>*/
Diagnostic(ErrorCode.ERR_InvalidExprTerm, ";").WithArguments(";").WithLocation(6, 42),
// CS0177: The out parameter 'y' must be assigned to before control leaves the current method
// /*<bind>*/void Foo(out int y) => ;/*</bind>*/
Diagnostic(ErrorCode.ERR_ParamUnassigned, "Foo").WithArguments("y").WithLocation(6, 24),
// CS8321: The local function 'Foo' is declared but never used
// /*<bind>*/void Foo(out int y) => ;/*</bind>*/
Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "Foo").WithArguments("Foo").WithLocation(6, 24)
// file.cs(6,40): error CS1525: Invalid expression term ';'
// /*<bind>*/void F(out int y) => ;/*</bind>*/
Diagnostic(ErrorCode.ERR_InvalidExprTerm, ";").WithArguments(";").WithLocation(6, 40),
// file.cs(6,24): error CS0177: The out parameter 'y' must be assigned to before control leaves the current method
// /*<bind>*/void F(out int y) => ;/*</bind>*/
Diagnostic(ErrorCode.ERR_ParamUnassigned, "F").WithArguments("y").WithLocation(6, 24),
// file.cs(6,24): warning CS8321: The local function 'F' is declared but never used
// /*<bind>*/void F(out int y) => ;/*</bind>*/
Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F").WithArguments("F").WithLocation(6, 24)
};

VerifyOperationTreeAndDiagnosticsForTest<LocalFunctionStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
Expand All @@ -359,23 +358,23 @@ class C
{
void M(int p)
{
/*<bind>*/void Foo( { }/*</bind>*/;
/*<bind>*/void F( { }/*</bind>*/;
}
}
";
string expectedOperationTree = @"
ILocalFunctionStatement (Local Function: void Foo()) (OperationKind.LocalFunctionStatement, IsInvalid) (Syntax: 'void Foo( { }')
ILocalFunctionStatement (Local Function: void F()) (OperationKind.LocalFunctionStatement, IsInvalid) (Syntax: 'void F( { }')
IBlockStatement (1 statements) (OperationKind.BlockStatement, IsInvalid) (Syntax: '{ }')
IReturnStatement (OperationKind.ReturnStatement, IsInvalid) (Syntax: '{ }')
ReturnedValue: null
";
var expectedDiagnostics = new DiagnosticDescription[] {
// CS1026: ) expected
// /*<bind>*/void Foo( { }/*</bind>*/;
Diagnostic(ErrorCode.ERR_CloseParenExpected, "{").WithLocation(6, 29),
// CS8321: The local function 'Foo' is declared but never used
// /*<bind>*/void Foo( { }/*</bind>*/;
Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "Foo").WithArguments("Foo").WithLocation(6, 24)
// file.cs(6,27): error CS1026: ) expected
// /*<bind>*/void F( { }/*</bind>*/;
Diagnostic(ErrorCode.ERR_CloseParenExpected, "{").WithLocation(6, 27),
// file.cs(6,24): warning CS8321: The local function 'F' is declared but never used
// /*<bind>*/void F( { }/*</bind>*/;
Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F").WithArguments("F").WithLocation(6, 24)
};

VerifyOperationTreeAndDiagnosticsForTest<LocalFunctionStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
Expand All @@ -389,24 +388,24 @@ class C
{
void M(int p)
{
/*<bind>*/X Foo() { }/*</bind>*/;
/*<bind>*/X F() { }/*</bind>*/;
}
}
";
string expectedOperationTree = @"
ILocalFunctionStatement (Local Function: X Foo()) (OperationKind.LocalFunctionStatement, IsInvalid) (Syntax: 'X Foo() { }')
ILocalFunctionStatement (Local Function: X F()) (OperationKind.LocalFunctionStatement, IsInvalid) (Syntax: 'X F() { }')
IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: '{ }')
";
var expectedDiagnostics = new DiagnosticDescription[] {
// CS0161: 'Foo()': not all code paths return a value
// /*<bind>*/X Foo() { }/*</bind>*/;
Diagnostic(ErrorCode.ERR_ReturnExpected, "Foo").WithArguments("Foo()").WithLocation(6, 21),
// CS0161: 'F()': not all code paths return a value
// /*<bind>*/X F() { }/*</bind>*/;
Diagnostic(ErrorCode.ERR_ReturnExpected, "F").WithArguments("F()").WithLocation(6, 21),
// CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)
// /*<bind>*/X Foo() { }/*</bind>*/;
// /*<bind>*/X F() { }/*</bind>*/;
Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "X").WithArguments("X").WithLocation(6, 19),
// CS8321: The local function 'Foo' is declared but never used
// /*<bind>*/X Foo() { }/*</bind>*/;
Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "Foo").WithArguments("Foo").WithLocation(6, 21)
// CS8321: The local function 'F' is declared but never used
// /*<bind>*/X F() { }/*</bind>*/;
Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "F").WithArguments("F").WithLocation(6, 21)
};

VerifyOperationTreeAndDiagnosticsForTest<LocalFunctionStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'a += b')
Public Sub VerifyOperationTree_IfStatement()
Dim source = <![CDATA[
Class C
Sub Foo(x As Integer)
Sub F(x As Integer)
If x <> 0 Then'BIND:"If x <> 0 Then"
System.Console.Write(x)
End If
End Sub
End Class
]]>.Value

Dim expectedOperationTree = <![CDATA[
Dim expectedOperationTree = <![CDATA[
IIfStatement (OperationKind.IfStatement) (Syntax: 'If x <> 0 T ... End If')
Condition: IBinaryOperatorExpression (BinaryOperationKind.IntegerNotEquals) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'x <> 0')
Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'x')
Expand All @@ -256,7 +256,7 @@ IIfStatement (OperationKind.IfStatement) (Syntax: 'If x <> 0 T ... End If')
Public Sub VerifyOperationTree_ForStatement()
Dim source = <![CDATA[
Class C
Sub Foo()
Sub F()
For i = 0 To 10'BIND:"For i = 0 To 10"
System.Console.Write(i)
Next
Expand Down
Loading

0 comments on commit f021ba8

Please sign in to comment.