From 1feeb9e51961aa4e606a6f6ef2b9060c77bc643c Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Thu, 14 Sep 2017 15:48:04 -0700 Subject: [PATCH] Remove CaseClause related Operation kinds which are already represented through CaseKind I also found that Range and Relational case clause have no tests in VB. Additionally, I also marked all OperationAnalyzerTests with CompilerTrait attribute so they don't get skipped in local trait based testing. Fixes #22129 --- .../Diagnostics/OperationAnalyzerTests.cs | 1 + ...tionTests_IParameterReferenceExpression.cs | 6 +- .../IOperationTests_IPatternSwitchCase.cs | 52 ++++++++--------- .../IOperationTests_InvalidStatement.cs | 4 +- .../Generated/Operations.xml.Generated.cs | 14 ++--- .../Core/Portable/Operations/OperationKind.cs | 21 ++----- .../Core/Portable/PublicAPI.Unshipped.txt | 14 ++--- .../Diagnostics/OperationAnalyzerTests.vb | 1 + .../IOperationTests_InvalidStatement.vb | 4 +- .../Semantic/Semantics/SelectCaseTests.vb | 56 ++++++++++++++++++- .../Diagnostics/OperationTestAnalyzer.cs | 10 +--- 11 files changed, 108 insertions(+), 75 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs b/src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs index cedddc22030..14286a3ec15 100644 --- a/src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs @@ -11,6 +11,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests { + [CompilerTrait(CompilerFeature.IOperation)] public class OperationAnalyzerTests : CompilingTestBase { private readonly static CSharpParseOptions patternParseOptions = TestOptions.Regular; diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs index eb989494216..59a4d978f1d 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs @@ -761,7 +761,7 @@ public void M(int x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case var y ... break;') Clauses: - IPatternCaseClause (Label Symbol: case var y when (x >= 10):) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case var y ... (x >= 10):') + IPatternCaseClause (Label Symbol: case var y when (x >= 10):) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case var y ... (x >= 10):') Pattern: IDeclarationPattern (Declared Symbol: System.Int32 y) (OperationKind.DeclarationPattern) (Syntax: 'var y') Guard Expression: IBinaryOperatorExpression (BinaryOperatorKind.GreaterThanOrEqual) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'x >= 10') Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'x') @@ -800,7 +800,7 @@ public void M(int x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case var y ... break;') Clauses: - IPatternCaseClause (Label Symbol: case var y when (x >= 10):) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case var y ... (x >= 10):') + IPatternCaseClause (Label Symbol: case var y when (x >= 10):) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case var y ... (x >= 10):') Pattern: IDeclarationPattern (Declared Symbol: System.Int32 y) (OperationKind.DeclarationPattern) (Syntax: 'var y') Guard Expression: IBinaryOperatorExpression (BinaryOperatorKind.GreaterThanOrEqual) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'x >= 10') Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'x') @@ -809,7 +809,7 @@ public void M(int x) IBranchStatement (BranchKind.Break) (OperationKind.BranchStatement) (Syntax: 'break;') ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'default:/*< ... break;') Clauses: - IDefaultCaseClause (CaseKind.Default) (OperationKind.DefaultCaseClause) (Syntax: 'default:') + IDefaultCaseClause (CaseKind.Default) (OperationKind.CaseClause) (Syntax: 'default:') Body: IBranchStatement (BranchKind.Break) (OperationKind.BranchStatement) (Syntax: 'break;') "; diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IPatternSwitchCase.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IPatternSwitchCase.cs index df67993daaa..9876e8d3f23 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IPatternSwitchCase.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IPatternSwitchCase.cs @@ -34,7 +34,7 @@ void M() Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case var y: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case var y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case var y:') + IPatternCaseClause (Label Symbol: case var y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case var y:') Pattern: IDeclarationPattern (Declared Symbol: System.Int32? y) (OperationKind.DeclarationPattern) (Syntax: 'var y') Guard Expression: null Body: @@ -70,7 +70,7 @@ void M() Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case int y: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case int y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case int y:') + IPatternCaseClause (Label Symbol: case int y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case int y:') Pattern: IDeclarationPattern (Declared Symbol: System.Int32 y) (OperationKind.DeclarationPattern) (Syntax: 'int y') Guard Expression: null Body: @@ -105,7 +105,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case X y:/* ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X y:') + IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X y:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: null Body: @@ -140,7 +140,7 @@ class X Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case T y:/* ... break;') Clauses: - IPatternCaseClause (Label Symbol: case T y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case T y:') + IPatternCaseClause (Label Symbol: case T y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case T y:') Pattern: IDeclarationPattern (Declared Symbol: T y) (OperationKind.DeclarationPattern) (Syntax: 'T y') Guard Expression: null Body: @@ -175,7 +175,7 @@ class X Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case dynami ... break;') Clauses: - IPatternCaseClause (Label Symbol: case dynamic y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case dynamic y:') + IPatternCaseClause (Label Symbol: case dynamic y:) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case dynamic y:') Pattern: IDeclarationPattern (Declared Symbol: dynamic y) (OperationKind.DeclarationPattern, IsInvalid) (Syntax: 'dynamic y') Guard Expression: null Body: @@ -216,7 +216,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case null: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case null:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case null:') + IPatternCaseClause (Label Symbol: case null:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case null:') Pattern: IConstantPattern (OperationKind.ConstantPattern) (Syntax: 'case null:') Value: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object, Constant: null) (Syntax: 'null') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null) @@ -226,7 +226,7 @@ void M(object x) IBranchStatement (BranchKind.Break) (OperationKind.BranchStatement) (Syntax: 'break;') ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case X y:/* ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X y:') + IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X y:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: null Body: @@ -262,13 +262,13 @@ void M(object x) Sections: ISwitchCase (2 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case null: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case null:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case null:') + IPatternCaseClause (Label Symbol: case null:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case null:') Pattern: IConstantPattern (OperationKind.ConstantPattern) (Syntax: 'case null:') Value: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object, Constant: null) (Syntax: 'null') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null) Operand: ILiteralExpression (OperationKind.LiteralExpression, Type: null, Constant: null) (Syntax: 'null') Guard Expression: null - IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X y:') + IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X y:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: null Body: @@ -305,16 +305,16 @@ void M(object x) Sections: ISwitchCase (3 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case null: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case null:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case null:') + IPatternCaseClause (Label Symbol: case null:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case null:') Pattern: IConstantPattern (OperationKind.ConstantPattern) (Syntax: 'case null:') Value: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object, Constant: null) (Syntax: 'null') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null) Operand: ILiteralExpression (OperationKind.LiteralExpression, Type: null, Constant: null) (Syntax: 'null') Guard Expression: null - IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X y:') + IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X y:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: null - IDefaultCaseClause (CaseKind.Default) (OperationKind.DefaultCaseClause) (Syntax: 'default:') + IDefaultCaseClause (CaseKind.Default) (OperationKind.CaseClause) (Syntax: 'default:') Body: IBranchStatement (BranchKind.Break) (OperationKind.BranchStatement) (Syntax: 'break;') "; @@ -347,7 +347,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case X y wh ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y when x != null:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X y when x != null:') + IPatternCaseClause (Label Symbol: case X y when x != null:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X y when x != null:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: IBinaryOperatorExpression (BinaryOperatorKind.NotEquals) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'x != null') Left: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'x') @@ -386,7 +386,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case X y wh ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y when x is X z :) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X y when x is X z :') + IPatternCaseClause (Label Symbol: case X y when x is X z :) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X y when x is X z :') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: IIsPatternExpression (OperationKind.IsPatternExpression, Type: System.Boolean) (Syntax: 'x is X z') Expression: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'x') @@ -423,7 +423,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case X y wh ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y when :) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case X y when :') + IPatternCaseClause (Label Symbol: case X y when :) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case X y when :') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: IInvalidExpression (OperationKind.InvalidExpression, Type: null, IsInvalid) (Syntax: '') Children(0) @@ -463,7 +463,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case X y wh ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y when x:) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case X y when x:') + IPatternCaseClause (Label Symbol: case X y when x:) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case X y when x:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Boolean, IsInvalid) (Syntax: 'x') Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) @@ -538,10 +538,10 @@ void M(object x) Sections: ISwitchCase (2 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case X y: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X y:') + IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X y:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern) (Syntax: 'X y') Guard Expression: null - IDefaultCaseClause (CaseKind.Default) (OperationKind.DefaultCaseClause) (Syntax: 'default:') + IDefaultCaseClause (CaseKind.Default) (OperationKind.CaseClause) (Syntax: 'default:') Body: IBranchStatement (BranchKind.Break) (OperationKind.BranchStatement) (Syntax: 'break;') "; @@ -576,7 +576,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case typeof ... break;') Clauses: - IPatternCaseClause (Label Symbol: case typeof(X):) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case typeof(X):') + IPatternCaseClause (Label Symbol: case typeof(X):) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case typeof(X):') Pattern: IConstantPattern (OperationKind.ConstantPattern, IsInvalid) (Syntax: 'case typeof(X):') Value: ITypeOfExpression (Type: X) (OperationKind.TypeOfExpression, Type: System.Type, IsInvalid) (Syntax: 'typeof(X)') Guard Expression: null @@ -619,7 +619,7 @@ void M(object x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case Undefi ... break;') Clauses: - IPatternCaseClause (Label Symbol: case UndefinedType y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case UndefinedType y:') + IPatternCaseClause (Label Symbol: case UndefinedType y:) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case UndefinedType y:') Pattern: IDeclarationPattern (Declared Symbol: UndefinedType y) (OperationKind.DeclarationPattern, IsInvalid) (Syntax: 'UndefinedType y') Guard Expression: null Body: @@ -658,7 +658,7 @@ void M(int? x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case X y:/* ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case X y:') + IPatternCaseClause (Label Symbol: case X y:) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case X y:') Pattern: IDeclarationPattern (Declared Symbol: X y) (OperationKind.DeclarationPattern, IsInvalid) (Syntax: 'X y') Guard Expression: null Body: @@ -698,7 +698,7 @@ void M(int? x) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case int y: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case int y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case int y:') + IPatternCaseClause (Label Symbol: case int y:) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case int y:') Pattern: IDeclarationPattern (Declared Symbol: System.Int32 y) (OperationKind.DeclarationPattern, IsInvalid) (Syntax: 'int y') Guard Expression: null Body: @@ -740,7 +740,7 @@ void M(int? x) Sections: ISwitchCase (1 case clauses, 2 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case /**/') + ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case /**/') Value: IInvalidExpression (OperationKind.InvalidExpression, Type: null, IsInvalid) (Syntax: '') Children(0) Body: @@ -802,21 +802,21 @@ void M(object p) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case int x: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case int x:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case int x:') + IPatternCaseClause (Label Symbol: case int x:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case int x:') Pattern: IDeclarationPattern (Declared Symbol: System.Int32 x) (OperationKind.DeclarationPattern) (Syntax: 'int x') Guard Expression: null Body: IBranchStatement (BranchKind.Break) (OperationKind.BranchStatement) (Syntax: 'break;') ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case int y: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case int y:) (CaseKind.Pattern) (OperationKind.PatternCaseClause, IsInvalid) (Syntax: 'case int y:') + IPatternCaseClause (Label Symbol: case int y:) (CaseKind.Pattern) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case int y:') Pattern: IDeclarationPattern (Declared Symbol: System.Int32 y) (OperationKind.DeclarationPattern, IsInvalid) (Syntax: 'int y') Guard Expression: null Body: IBranchStatement (BranchKind.Break) (OperationKind.BranchStatement) (Syntax: 'break;') ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'case X z: ... break;') Clauses: - IPatternCaseClause (Label Symbol: case X z:) (CaseKind.Pattern) (OperationKind.PatternCaseClause) (Syntax: 'case X z:') + IPatternCaseClause (Label Symbol: case X z:) (CaseKind.Pattern) (OperationKind.CaseClause) (Syntax: 'case X z:') Pattern: IDeclarationPattern (Declared Symbol: X z) (OperationKind.DeclarationPattern) (Syntax: 'X z') Guard Expression: null Body: diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_InvalidStatement.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_InvalidStatement.cs index b67e2a45010..9f99e4c94db 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_InvalidStatement.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_InvalidStatement.cs @@ -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.CSharp.Test.Utilities; @@ -114,7 +114,7 @@ static void Main(string[] args) Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'case 1: ... break;') Clauses: - ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.SingleValueCaseClause, IsInvalid) (Syntax: 'case 1:') + ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.CaseClause, IsInvalid) (Syntax: 'case 1:') Value: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.String, IsInvalid) (Syntax: '1') Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1, IsInvalid) (Syntax: '1') diff --git a/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs b/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs index 8bdc47ed114..332dbf1c18c 100644 --- a/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs +++ b/src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs @@ -807,8 +807,8 @@ public override void Accept(OperationVisitor visitor) /// internal abstract partial class CaseClause : Operation, ICaseClause { - protected CaseClause(CaseKind caseKind, OperationKind kind, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional constantValue, bool isImplicit) : - base(kind, semanticModel, syntax, type, constantValue, isImplicit) + protected CaseClause(CaseKind caseKind, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional constantValue, bool isImplicit) : + base(OperationKind.CaseClause, semanticModel, syntax, type, constantValue, isImplicit) { CaseKind = caseKind; } @@ -3797,7 +3797,7 @@ public override void Accept(OperationVisitor visitor) internal abstract partial class BaseRangeCaseClause : CaseClause, IRangeCaseClause { public BaseRangeCaseClause(CaseKind caseKind, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional constantValue, bool isImplicit) : - base(caseKind, OperationKind.RangeCaseClause, semanticModel, syntax, type, constantValue, isImplicit) + base(caseKind, semanticModel, syntax, type, constantValue, isImplicit) { } @@ -3872,7 +3872,7 @@ internal sealed partial class LazyRangeCaseClause : BaseRangeCaseClause, IRangeC internal abstract partial class BaseRelationalCaseClause : CaseClause, IRelationalCaseClause { public BaseRelationalCaseClause(BinaryOperatorKind relation, CaseKind caseKind, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional constantValue, bool isImplicit) : - base(caseKind, OperationKind.RelationalCaseClause, semanticModel, syntax, type, constantValue, isImplicit) + base(caseKind, semanticModel, syntax, type, constantValue, isImplicit) { Relation = relation; } @@ -4018,7 +4018,7 @@ public LazyReturnStatement(OperationKind kind, Lazy returnedValue, S internal abstract partial class BaseSingleValueCaseClause : CaseClause, ISingleValueCaseClause { public BaseSingleValueCaseClause(CaseKind caseKind, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional constantValue, bool isImplicit) : - base(caseKind, OperationKind.SingleValueCaseClause, semanticModel, syntax, type, constantValue, isImplicit) + base(caseKind, semanticModel, syntax, type, constantValue, isImplicit) { } @@ -4081,7 +4081,7 @@ internal sealed partial class LazySingleValueCaseClause : BaseSingleValueCaseCla internal sealed partial class DefaultCaseClause : CaseClause, IDefaultCaseClause { public DefaultCaseClause(SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional constantValue, bool isImplicit) : - base(CaseKind.Default, OperationKind.DefaultCaseClause, semanticModel, syntax, type, constantValue, isImplicit) + base(CaseKind.Default, semanticModel, syntax, type, constantValue, isImplicit) { } public override IEnumerable Children @@ -5364,7 +5364,7 @@ public override void Accept(OperationVisitor visitor) internal abstract partial class BasePatternCaseClause : CaseClause, IPatternCaseClause { protected BasePatternCaseClause(ILabelSymbol label, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional constantValue, bool isImplicit) : - base(CaseKind.Pattern, OperationKind.PatternCaseClause, semanticModel, syntax, type, constantValue, isImplicit) + base(CaseKind.Pattern, semanticModel, syntax, type, constantValue, isImplicit) { Label = label; } diff --git a/src/Compilers/Core/Portable/Operations/OperationKind.cs b/src/Compilers/Core/Portable/Operations/OperationKind.cs index e39cee77e5e..2fa88bd2d5f 100644 --- a/src/Compilers/Core/Portable/Operations/OperationKind.cs +++ b/src/Compilers/Core/Portable/Operations/OperationKind.cs @@ -196,26 +196,17 @@ public enum OperationKind /// Indicates an . SwitchCase = 0x409, - /// Indicates an . - SingleValueCaseClause = 0x40a, - /// Indicates an . - RelationalCaseClause = 0x40b, - /// Indicates an . - RangeCaseClause = 0x40c, + /// Indicates different kinds of switch case clauses as defined by . + CaseClause = 0x40a, /// Indicates an . - InterpolatedStringText = 0x40d, + InterpolatedStringText = 0x40b, /// Indicates an . - Interpolation = 0x40e, + Interpolation = 0x40c, /// Indicates an . - ConstantPattern = 0x40f, + ConstantPattern = 0x40d, /// Indicates an . - DeclarationPattern = 0x410, - /// Indicates an . - PatternCaseClause = 0x411, - - /// Indicates an . - DefaultCaseClause = 0x412, + DeclarationPattern = 0x40e, } } diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index 644001ed314..548b51341a8 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -59,6 +59,7 @@ Microsoft.CodeAnalysis.OperationKind.AwaitExpression = 279 -> Microsoft.CodeAnal Microsoft.CodeAnalysis.OperationKind.BinaryOperatorExpression = 270 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.BlockStatement = 2 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.BranchStatement = 8 -> Microsoft.CodeAnalysis.OperationKind +Microsoft.CodeAnalysis.OperationKind.CaseClause = 1034 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.CatchClause = 1032 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.CoalesceExpression = 272 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.CollectionElementInitializerExpression = 290 -> Microsoft.CodeAnalysis.OperationKind @@ -66,10 +67,9 @@ Microsoft.CodeAnalysis.OperationKind.CompoundAssignmentExpression = 281 -> Micro Microsoft.CodeAnalysis.OperationKind.ConditionalAccessExpression = 284 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.ConditionalAccessInstanceExpression = 285 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.ConditionalExpression = 271 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.ConstantPattern = 1039 -> Microsoft.CodeAnalysis.OperationKind +Microsoft.CodeAnalysis.OperationKind.ConstantPattern = 1037 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.ConversionExpression = 258 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.DeclarationPattern = 1040 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.DefaultCaseClause = 1042 -> Microsoft.CodeAnalysis.OperationKind +Microsoft.CodeAnalysis.OperationKind.DeclarationPattern = 1038 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.DefaultValueExpression = 512 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.DynamicMemberReferenceExpression = 294 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.DynamicObjectCreationExpression = 293 -> Microsoft.CodeAnalysis.OperationKind @@ -84,8 +84,8 @@ Microsoft.CodeAnalysis.OperationKind.IfStatement = 5 -> Microsoft.CodeAnalysis.O Microsoft.CodeAnalysis.OperationKind.IncrementExpression = 518 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.InstanceReferenceExpression = 277 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.InterpolatedStringExpression = 286 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.InterpolatedStringText = 1037 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.Interpolation = 1038 -> Microsoft.CodeAnalysis.OperationKind +Microsoft.CodeAnalysis.OperationKind.InterpolatedStringText = 1035 -> Microsoft.CodeAnalysis.OperationKind +Microsoft.CodeAnalysis.OperationKind.Interpolation = 1036 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.InvalidExpression = 256 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.InvalidStatement = 1 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.InvocationExpression = 259 -> Microsoft.CodeAnalysis.OperationKind @@ -107,15 +107,11 @@ Microsoft.CodeAnalysis.OperationKind.OmittedArgumentExpression = 768 -> Microsof Microsoft.CodeAnalysis.OperationKind.ParameterInitializer = 1028 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.ParameterReferenceExpression = 262 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.ParenthesizedExpression = 282 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.PatternCaseClause = 1041 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.PlaceholderExpression = 770 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.PropertyInitializer = 1027 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.PropertyReferenceExpression = 266 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.RangeCaseClause = 1036 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.RelationalCaseClause = 1035 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.ReturnStatement = 11 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.SimpleAssignmentExpression = 280 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.SingleValueCaseClause = 1034 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.SizeOfExpression = 514 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.StopStatement = 80 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.SwitchCase = 1033 -> Microsoft.CodeAnalysis.OperationKind diff --git a/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb index 37f5d29722d..0977b48e9f4 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb @@ -9,6 +9,7 @@ Imports Xunit Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics + Public Class OperationAnalyzerTests Inherits BasicTestBase diff --git a/src/Compilers/VisualBasic/Test/Semantic/IOperation/IOperationTests_InvalidStatement.vb b/src/Compilers/VisualBasic/Test/Semantic/IOperation/IOperationTests_InvalidStatement.vb index 49db210696a..518292b4bcf 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/IOperation/IOperationTests_InvalidStatement.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/IOperation/IOperationTests_InvalidStatement.vb @@ -57,7 +57,7 @@ ISwitchStatement (1 cases) (OperationKind.SwitchStatement, IsInvalid) (Syntax: ' Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'Case 1') Clauses: - ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.SingleValueCaseClause) (Syntax: '1') + ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.CaseClause) (Syntax: '1') Value: null Body: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: 'Case 1') @@ -94,7 +94,7 @@ ISwitchStatement (1 cases) (OperationKind.SwitchStatement, IsInvalid) (Syntax: ' Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase, IsInvalid) (Syntax: 'Case x ... Exit Select') Clauses: - ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.SingleValueCaseClause, IsInvalid) (Syntax: 'x') + ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.CaseClause, IsInvalid) (Syntax: 'x') Value: null Body: IBlockStatement (1 statements) (OperationKind.BlockStatement, IsInvalid) (Syntax: 'Case x ... Exit Select') diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTests.vb index 72c9ecc3ec8..1b610786a8b 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/SelectCaseTests.vb @@ -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. Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -409,6 +409,56 @@ End Module Assert.Equal(1, semanticSummary.ConstantValue.Value) End Sub + + Public Sub SelectCase_RelationalCaseClauseExpression_IOperation() + Dim source = .Value + + Dim expectedOperationTree = .Value + + Dim expectedDiagnostics = String.Empty + + VerifyOperationTreeAndDiagnosticsForTest(Of RelationalCaseClauseSyntax)(source, expectedOperationTree, expectedDiagnostics) + End Sub + + + + Public Sub SelectCase_RangeCaseClauseExpression_IOperation() + Dim source = .Value + + Dim expectedOperationTree = .Value + + Dim expectedDiagnostics = String.Empty + + VerifyOperationTreeAndDiagnosticsForTest(Of RangeCaseClauseSyntax)(source, expectedOperationTree, expectedDiagnostics) + End Sub + Public Sub SelectCase_RangeCaseClauseExpression_MethodCall() Dim compilation = CreateCompilationWithMscorlib( @@ -589,7 +639,7 @@ ISwitchStatement (2 cases) (OperationKind.SwitchStatement) (Syntax: 'Select Case Sections: ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'Case Functi ... e("Failed")') Clauses: - ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.SingleValueCaseClause) (Syntax: 'Function() 5') + ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.CaseClause) (Syntax: 'Function() 5') Value: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'Function() 5') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null) Operand: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: Function () As System.Int32) (Syntax: 'Function() 5') @@ -615,7 +665,7 @@ ISwitchStatement (2 cases) (OperationKind.SwitchStatement) (Syntax: 'Select Case OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) ISwitchCase (1 case clauses, 1 statements) (OperationKind.SwitchCase) (Syntax: 'Case Else ... Succeeded")') Clauses: - IDefaultCaseClause (CaseKind.Default) (OperationKind.DefaultCaseClause) (Syntax: 'Case Else') + IDefaultCaseClause (CaseKind.Default) (OperationKind.CaseClause) (Syntax: 'Case Else') Body: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: 'Case Else ... Succeeded")') IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'System.Cons ... Succeeded")') diff --git a/src/Test/Utilities/Portable/Diagnostics/OperationTestAnalyzer.cs b/src/Test/Utilities/Portable/Diagnostics/OperationTestAnalyzer.cs index 7431193b491..52c6988dbe0 100644 --- a/src/Test/Utilities/Portable/Diagnostics/OperationTestAnalyzer.cs +++ b/src/Test/Utilities/Portable/Diagnostics/OperationTestAnalyzer.cs @@ -911,10 +911,7 @@ public sealed override void Initialize(AnalysisContext context) { switch (operationContext.Operation.Kind) { - case OperationKind.SingleValueCaseClause: - case OperationKind.RelationalCaseClause: - case OperationKind.RangeCaseClause: - case OperationKind.DefaultCaseClause: + case OperationKind.CaseClause: var caseClause = (ICaseClause)operationContext.Operation; if (caseClause.CaseKind == CaseKind.Default) { @@ -931,10 +928,7 @@ public sealed override void Initialize(AnalysisContext context) } }, OperationKind.SwitchCase, - OperationKind.SingleValueCaseClause, - OperationKind.RangeCaseClause, - OperationKind.RelationalCaseClause, - OperationKind.DefaultCaseClause); + OperationKind.CaseClause); } private static void Report(OperationAnalysisContext context, SyntaxNode syntax, DiagnosticDescriptor descriptor) -- GitLab