From 13a6f436031a1251758792485f5b98dfd53bbe8c Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Wed, 8 Nov 2017 16:03:31 -0800 Subject: [PATCH] Small typo fix, add a couple of more tests. --- .../IOperationTests_IVariableDeclaration.cs | 63 ++++++++++++++++++- .../Generated/Operations.xml.Generated.cs | 7 +-- .../IVariableDeclaratorOperation.cs | 2 +- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IVariableDeclaration.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IVariableDeclaration.cs index 8556c85edc91c..7173edba18c84 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IVariableDeclaration.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IVariableDeclaration.cs @@ -590,7 +590,7 @@ void M1() [CompilerTrait(CompilerFeature.IOperation)] [Fact] - public void IVariableDeclaration_InvalidIgnoredArguments_VerifyChildren() + public void IVariableDeclaration_InvalidIgnoredArgumentsWithInitializer_VerifyChildren() { string source = @" class C @@ -610,6 +610,67 @@ void M1() Assert.Equal(OperationKind.VariableInitializer, declarator.Children.ElementAt(1).Kind); } + [CompilerTrait(CompilerFeature.IOperation)] + [Fact] + public void IVariableDeclaration_InvalidIgnoredArguments_VerifyChildren() + { + string source = @" +class C +{ + void M1() + { + int /**/x[10]/**/; + } +} +"; + + var compilation = CreateCompilation(source); + (var operation, _) = GetOperationAndSyntaxForTest(compilation); + var declarator = (IVariableDeclaratorOperation)operation; + Assert.Equal(1, declarator.Children.Count()); + Assert.Equal(OperationKind.Literal, declarator.Children.First().Kind); + } + + [CompilerTrait(CompilerFeature.IOperation)] + [Fact] + public void IVariableDeclaration_WithInitializer_VerifyChildren() + { + string source = @" +class C +{ + void M1() + { + int /**/x = 1/**/; + } +} +"; + + var compilation = CreateCompilation(source); + (var operation, _) = GetOperationAndSyntaxForTest(compilation); + var declarator = (IVariableDeclaratorOperation)operation; + Assert.Equal(1, declarator.Children.Count()); + Assert.Equal(OperationKind.VariableInitializer, declarator.Children.ElementAt(0).Kind); + } + + [CompilerTrait(CompilerFeature.IOperation)] + [Fact] + public void IVariableDeclaration_NoChildren() + { + string source = @" +class C +{ + void M1() + { + int /**/x/**/; + } +} +"; + + var compilation = CreateCompilation(source); + (var operation, _) = GetOperationAndSyntaxForTest(compilation); + Assert.Empty(operation.Children); + } + #endregion #region Fixed Statements diff --git a/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs b/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs index 1bc83fe84bcdc..6caeae24de2a6 100644 --- a/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs +++ b/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs @@ -5436,12 +5436,9 @@ public override IEnumerable Children { get { - if (!IgnoredArguments.IsEmpty) + foreach (var arg in IgnoredArguments) { - foreach (var arg in IgnoredArguments) - { - yield return arg; - } + yield return arg; } if (Initializer != null) { diff --git a/src/Compilers/Core/Portable/Operations/IVariableDeclaratorOperation.cs b/src/Compilers/Core/Portable/Operations/IVariableDeclaratorOperation.cs index 19a1ba88d3662..1372cdea527eb 100644 --- a/src/Compilers/Core/Portable/Operations/IVariableDeclaratorOperation.cs +++ b/src/Compilers/Core/Portable/Operations/IVariableDeclaratorOperation.cs @@ -39,7 +39,7 @@ public interface IVariableDeclaratorOperation : IOperation IVariableInitializerOperation Initializer { get; } /// - /// Additional arguments supplied to the declarator in error cases, ignored by the compiler. This only used for C# cases, of + /// Additional arguments supplied to the declarator in error cases, ignored by the compiler. This only used for the C# case of /// DeclaredArgumentSyntax nodes on a VariableDeclaratorSyntax. /// ImmutableArray IgnoredArguments { get; }