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

ISwitchExpressionOperation.IsExhaustive API extension #52703

Merged
merged 33 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
17b8d00
ReportedNotExhaustive
bernd5 Apr 13, 2021
d885890
Merge commit '17b8d002454e6aa1831c49b64f21a8d4417bbe56' into ioperati…
bernd5 Apr 13, 2021
00f69d7
Merge branch 'main' into ioperation_switchexpr_exhaustive
bernd5 Apr 17, 2021
0e640e7
Property added
bernd5 Apr 17, 2021
ca7cb17
test extended
bernd5 Apr 17, 2021
dfecc38
test extended
bernd5 Apr 17, 2021
b5cc68a
Merge remote-tracking branch 'dotnet-roslyn/main' into ioperation_swi…
bernd5 Apr 18, 2021
5d3cb3d
added ISwitchExpressionOperation.IsExhaustive.get
bernd5 Apr 18, 2021
a17e600
test added
bernd5 Apr 18, 2021
a6bbeb4
isExhaustive test extended
bernd5 Apr 18, 2021
4caaed0
test adjusted
bernd5 Apr 18, 2021
955cd47
Update src/Compilers/Core/Portable/Operations/OperationInterfaces.xml
bernd5 Apr 19, 2021
20ba902
check DefaultLabel
bernd5 Apr 28, 2021
ad617af
Merge branch 'ioperation_switchexpr_exhaustive' of https://github.com…
bernd5 Apr 28, 2021
0572675
check DefaultLabel
bernd5 Apr 28, 2021
cdf9f21
fix format issue
bernd5 Apr 28, 2021
17bda26
CSharpOperationFactory: isExhaustive-eval should be based on DefaultL…
bernd5 Apr 28, 2021
6a6c4b1
force BoundConvertedSwitchExpression
bernd5 Apr 28, 2021
028ea86
rerun of CSharpSyntaxGenerator
bernd5 Apr 28, 2021
dc4cd40
Usage of IsExhaustive in TestOperationVisitor
bernd5 Apr 28, 2021
a1633ac
Add throw SwitchExpressionException in ControlFlowGraphBuilder only i…
bernd5 May 5, 2021
aac0c02
Update TestOperationVisitor.cs
bernd5 May 5, 2021
546a413
Format
bernd5 May 5, 2021
3c22f98
Revert "Add throw SwitchExpressionException in ControlFlowGraphBuilde…
bernd5 May 18, 2021
4d13d79
Revert "Revert "Add throw SwitchExpressionException in ControlFlowGra…
bernd5 May 18, 2021
6e4a60d
adjusted linkToPrevious
bernd5 May 18, 2021
104149d
Update src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
bernd5 May 18, 2021
a97a8f2
Update src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
bernd5 May 18, 2021
a0aa8d4
Update src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
bernd5 May 18, 2021
a0c8920
Update src/Compilers/Test/Core/Compilation/TestOperationVisitor.cs
bernd5 May 19, 2021
ccc5610
Don't generate branches for discard patterns in switch expressions.
333fred May 27, 2021
0a9ba2b
Fix bug in capturing, look through all expressions in the final block…
333fred May 28, 2021
05d1982
revert ControlFlowGraphBuilder commits
bernd5 May 28, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -2154,9 +2154,22 @@ private ISwitchExpressionOperation CreateBoundSwitchExpressionOperation(BoundSwi
{
bernd5 marked this conversation as resolved.
Show resolved Hide resolved
IOperation value = Create(boundSwitchExpression.Expression);
ImmutableArray<ISwitchExpressionArmOperation> arms = CreateFromArray<BoundSwitchExpressionArm, ISwitchExpressionArmOperation>(boundSwitchExpression.SwitchArms);

bool isExhaustive = !boundSwitchExpression.ReportedNotExhaustive;
bernd5 marked this conversation as resolved.
Show resolved Hide resolved
bernd5 marked this conversation as resolved.
Show resolved Hide resolved
if (isExhaustive && !boundSwitchExpression.HasAnyErrors)
{
var reachableLabelsCount = boundSwitchExpression.DecisionDag.ReachableLabels.Count;
var armsCount = arms.Length;
if (reachableLabelsCount == armsCount + 1)
{
isExhaustive = false;
}
}

return new SwitchExpressionOperation(
value,
arms,
isExhaustive,
_semanticModel,
boundSwitchExpression.Syntax,
boundSwitchExpression.GetPublicTypeSymbol(),
Expand Down
18 changes: 9 additions & 9 deletions src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4880,7 +4880,7 @@ public class B
var switchExpressions = tree.GetRoot().DescendantNodes().OfType<SwitchExpressionSyntax>().ToArray();

VerifyOperationTreeForNode(compilation, model, switchExpressions[0], @"
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... 1, _ => 2 }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... 1, _ => 2 }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsInvalid) (Syntax: '1')
Arms(2):
Expand All @@ -4899,7 +4899,7 @@ public class B
");

VerifyOperationTreeForNode(compilation, model, switchExpressions[1], @"
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... > new B() }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... > new B() }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsInvalid) (Syntax: '1')
Arms(2):
Expand Down Expand Up @@ -4930,7 +4930,7 @@ public class B
");

VerifyOperationTreeForNode(compilation, model, switchExpressions[2], @"
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: ?, IsInvalid) (Syntax: '1 switch { ... ing.Empty }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: ?, IsInvalid) (Syntax: '1 switch { ... ing.Empty }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsInvalid) (Syntax: '1')
Arms(2):
Expand Down Expand Up @@ -5012,7 +5012,7 @@ public class B
Instance Receiver:
null
Right:
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... 1, _ => 2 }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... 1, _ => 2 }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsInvalid) (Syntax: '1')
Arms(2):
Expand Down Expand Up @@ -5040,7 +5040,7 @@ public class B
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Int32, IsInvalid, IsImplicit) (Syntax: '1 switch { ... > new B() }')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... > new B() }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: System.Int32, IsInvalid) (Syntax: '1 switch { ... > new B() }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1, IsInvalid) (Syntax: '1')
Arms(2):
Expand Down Expand Up @@ -5080,7 +5080,7 @@ public class B
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Int32, IsInvalid, IsImplicit) (Syntax: '1 switch { ... ing.Empty }')
Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: ?, IsInvalid) (Syntax: '1 switch { ... ing.Empty }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: ?, IsInvalid) (Syntax: '1 switch { ... ing.Empty }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1')
Arms(2):
Expand Down Expand Up @@ -5163,7 +5163,7 @@ public class B
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: ?, IsImplicit) (Syntax: '1 switch { ... 1, _ => 2 }')
Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: System.Int32) (Syntax: '1 switch { ... 1, _ => 2 }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: System.Int32) (Syntax: '1 switch { ... 1, _ => 2 }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1')
Arms(2):
Expand All @@ -5190,7 +5190,7 @@ public class B
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: ?, IsImplicit) (Syntax: '1 switch { ... > new B() }')
Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: ?) (Syntax: '1 switch { ... > new B() }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: ?) (Syntax: '1 switch { ... > new B() }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1')
Arms(2):
Expand Down Expand Up @@ -5229,7 +5229,7 @@ public class B
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: ?, IsImplicit) (Syntax: '1 switch { ... ing.Empty }')
Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
ISwitchExpressionOperation (2 arms) (OperationKind.SwitchExpression, Type: ?) (Syntax: '1 switch { ... ing.Empty }')
ISwitchExpressionOperation (2 arms, IsExhaustive: True) (OperationKind.SwitchExpression, Type: ?) (Syntax: '1 switch { ... ing.Empty }')
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1')
Arms(2):
Expand Down
Loading