Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,7 @@ private BoundExpression BindIsOperator(BinaryExpressionSyntax node, DiagnosticBa
}

var boundConstantPattern = BindConstantPattern(
node.Right, operand, operand.Type, node.Right, node.Right.HasErrors, isPatternDiagnostics, out wasExpression, wasSwitchCase: false);
node.Right, operand.Type, node.Right, node.Right.HasErrors, isPatternDiagnostics, out wasExpression, wasSwitchCase: false);
if (wasExpression)
{
isTypeDiagnostics.Free();
Expand Down
25 changes: 8 additions & 17 deletions src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ private BoundExpression BindIsPatternExpression(IsPatternExpressionSyntax node,
}
}

var pattern = BindPattern(node.Pattern, expression, expressionType, hasErrors, diagnostics);
var pattern = BindPattern(node.Pattern, expressionType, hasErrors, diagnostics);
return new BoundIsPatternExpression(
node, expression, pattern, GetSpecialType(SpecialType.System_Boolean, diagnostics, node), hasErrors);
}

internal BoundPattern BindPattern(
PatternSyntax node,
BoundExpression operand,
TypeSymbol operandType,
bool hasErrors,
DiagnosticBag diagnostics,
Expand All @@ -44,11 +43,11 @@ internal BoundPattern BindPattern(
{
case SyntaxKind.DeclarationPattern:
return BindDeclarationPattern(
(DeclarationPatternSyntax)node, operand, operandType, hasErrors, diagnostics);
(DeclarationPatternSyntax)node, operandType, hasErrors, diagnostics);

case SyntaxKind.ConstantPattern:
return BindConstantPattern(
(ConstantPatternSyntax)node, operand, operandType, hasErrors, diagnostics, wasSwitchCase);
(ConstantPatternSyntax)node, operandType, hasErrors, diagnostics, wasSwitchCase);

default:
throw ExceptionUtilities.UnexpectedValue(node.Kind());
Expand All @@ -57,19 +56,17 @@ internal BoundPattern BindPattern(

private BoundConstantPattern BindConstantPattern(
ConstantPatternSyntax node,
BoundExpression operand,
TypeSymbol operandType,
bool hasErrors,
DiagnosticBag diagnostics,
bool wasSwitchCase)
{
bool wasExpression;
return BindConstantPattern(node, operand, operandType, node.Expression, hasErrors, diagnostics, out wasExpression, wasSwitchCase);
return BindConstantPattern(node, operandType, node.Expression, hasErrors, diagnostics, out wasExpression, wasSwitchCase);
}

internal BoundConstantPattern BindConstantPattern(
CSharpSyntaxNode node,
BoundExpression operand,
TypeSymbol operandType,
ExpressionSyntax patternExpression,
bool hasErrors,
Expand Down Expand Up @@ -133,7 +130,6 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
/// </summary>
private bool CheckValidPatternType(
CSharpSyntaxNode typeSyntax,
BoundExpression operand,
TypeSymbol operandType,
TypeSymbol patternType,
bool patternTypeWasInSource,
Expand All @@ -143,10 +139,6 @@ private bool CheckValidPatternType(
Debug.Assert((object)operandType != null);
Debug.Assert((object)patternType != null);

// Because we do not support recursive patterns, we always have an operand
Debug.Assert((object)operand != null);
// Once we support recursive patterns that will be relaxed.

if (operandType.IsErrorType() || patternType.IsErrorType())
{
return false;
Expand All @@ -171,7 +163,7 @@ private bool CheckValidPatternType(
}

HashSet<DiagnosticInfo> useSiteDiagnostics = null;
var matchPossible = ExpressionOfTypeMatchesPatternType(Conversions, operandType, patternType, ref useSiteDiagnostics, out Conversion conversion, operandConstantValue: null, operandCouldBeNull: true);
var matchPossible = ExpressionOfTypeMatchesPatternType(Conversions, operandType, patternType, ref useSiteDiagnostics, out Conversion conversion, operandCouldBeNull: true);
diagnostics.Add(typeSyntax, useSiteDiagnostics);
if (matchPossible != false)
{
Expand Down Expand Up @@ -211,7 +203,6 @@ private bool CheckValidPatternType(
TypeSymbol patternType,
ref HashSet<DiagnosticInfo> useSiteDiagnostics,
out Conversion conversion,
ConstantValue operandConstantValue = null,
bool operandCouldBeNull = false)
{
Debug.Assert((object)expressionType != null);
Expand All @@ -222,6 +213,7 @@ private bool CheckValidPatternType(
}

conversion = conversions.ClassifyConversionFromType(expressionType, patternType, ref useSiteDiagnostics);
const ConstantValue operandConstantValue = null; // subsumption always ignores the *value* of the expression.
var result = Binder.GetIsOperatorConstantResult(expressionType, patternType, conversion.Kind, operandConstantValue, operandCouldBeNull);
return
(result == null) ? (bool?)null :
Expand All @@ -232,12 +224,11 @@ private bool CheckValidPatternType(

private BoundPattern BindDeclarationPattern(
DeclarationPatternSyntax node,
BoundExpression operand,
TypeSymbol operandType,
bool hasErrors,
DiagnosticBag diagnostics)
{
Debug.Assert(operand != null && operandType != (object)null);
Debug.Assert(operandType != (object)null);

var typeSyntax = node.Type;

Expand All @@ -262,7 +253,7 @@ private BoundPattern BindDeclarationPattern(
}
else
{
hasErrors |= CheckValidPatternType(typeSyntax, operand, operandType, declType,
hasErrors |= CheckValidPatternType(typeSyntax, operandType, declType,
isVar: isVar, patternTypeWasInSource: true, diagnostics: diagnostics);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/PatternSwitchBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private BoundPatternSwitchLabel BindPatternSwitchSectionLabel(
var caseLabelSyntax = (CaseSwitchLabelSyntax)node;
bool wasExpression;
var pattern = sectionBinder.BindConstantPattern(
node, boundSwitchExpression, boundSwitchExpression.Type, caseLabelSyntax.Value, node.HasErrors, diagnostics, out wasExpression, wasSwitchCase: true);
node, boundSwitchExpression.Type, caseLabelSyntax.Value, node.HasErrors, diagnostics, out wasExpression, wasSwitchCase: true);
bool hasErrors = pattern.HasErrors;
var constantValue = pattern.ConstantValue;
if (!hasErrors &&
Expand Down Expand Up @@ -228,7 +228,7 @@ private BoundPatternSwitchLabel BindPatternSwitchSectionLabel(
{
var matchLabelSyntax = (CasePatternSwitchLabelSyntax)node;
var pattern = sectionBinder.BindPattern(
matchLabelSyntax.Pattern, boundSwitchExpression, boundSwitchExpression.Type, node.HasErrors, diagnostics, wasSwitchCase: true);
matchLabelSyntax.Pattern, boundSwitchExpression.Type, node.HasErrors, diagnostics, wasSwitchCase: true);
return new BoundPatternSwitchLabel(node, label, pattern,
matchLabelSyntax.WhenClause != null ? sectionBinder.BindBooleanExpression(matchLabelSyntax.WhenClause.Condition, diagnostics) : null,
true, node.HasErrors);
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/SwitchBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void BuildSwitchLabels(SyntaxList<SwitchLabelSyntax> labelsSyntax, Binde
// bind the pattern, to cause its pattern variables to be inferred if necessary
var matchLabel = (CasePatternSwitchLabelSyntax)labelSyntax;
var pattern = sectionBinder.BindPattern(
matchLabel.Pattern, SwitchGoverningExpression, SwitchGoverningType, labelSyntax.HasErrors, tempDiagnosticBag, wasSwitchCase: true);
matchLabel.Pattern, SwitchGoverningType, labelSyntax.HasErrors, tempDiagnosticBag, wasSwitchCase: true);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private DecisionTree AddByValue(DecisionTree.ByType byType, BoundConstantPattern
/// </summary>
internal bool? ExpressionOfTypeMatchesPatternType(TypeSymbol expressionType, TypeSymbol patternType, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
return Binder.ExpressionOfTypeMatchesPatternType(this._conversions, expressionType, patternType, ref _useSiteDiagnostics, out Conversion conversion, null, false);
return Binder.ExpressionOfTypeMatchesPatternType(this._conversions, expressionType, patternType, ref _useSiteDiagnostics, out Conversion conversion, operandCouldBeNull: false);
}

private DecisionTree AddByType(DecisionTree decision, TypeSymbol type, DecisionMaker makeDecision)
Expand Down