提交 b38ee703 编写于 作者: J Jared Parsons 提交者: GitHub

Merge pull request #13933 from gafter/dev15-preview-5-13884

Avoid a null value key in the decision tree in error recovery situations.
......@@ -224,7 +224,7 @@ private void AddToDecisionTree(DecisionTree decisionTree, BoundPatternSwitchLabe
case BoundKind.ConstantPattern:
{
var constantPattern = (BoundConstantPattern)pattern;
AddByValue(decisionTree, constantPattern.Value, (e, t) => new DecisionTree.Guarded(e, t, default(ImmutableArray<KeyValuePair<BoundExpression, LocalSymbol>>), _section, guard, label), label.HasErrors);
AddByValue(decisionTree, constantPattern.Value, (e, t) => new DecisionTree.Guarded(e, t, default(ImmutableArray<KeyValuePair<BoundExpression, LocalSymbol>>), _section, guard, label));
break;
}
case BoundKind.DeclarationPattern:
......@@ -475,7 +475,7 @@ private ErrorCode CheckSubsumed(BoundPattern pattern, DecisionTree decisionTree,
BoundExpression expression,
TypeSymbol type);
private DecisionTree AddByValue(DecisionTree decision, BoundExpression value, DecisionMaker makeDecision, bool hasErrors)
private DecisionTree AddByValue(DecisionTree decision, BoundExpression value, DecisionMaker makeDecision)
{
if (decision.MatchIsComplete)
{
......@@ -487,17 +487,17 @@ private DecisionTree AddByValue(DecisionTree decision, BoundExpression value, De
switch (decision.Kind)
{
case DecisionTree.DecisionKind.ByType:
return AddByValue((DecisionTree.ByType)decision, value, makeDecision, hasErrors);
return AddByValue((DecisionTree.ByType)decision, value, makeDecision);
case DecisionTree.DecisionKind.ByValue:
return AddByValue((DecisionTree.ByValue)decision, value, makeDecision, hasErrors);
return AddByValue((DecisionTree.ByValue)decision, value, makeDecision);
case DecisionTree.DecisionKind.Guarded:
return AddByValue((DecisionTree.Guarded)decision, value, makeDecision, hasErrors);
return AddByValue((DecisionTree.Guarded)decision, value, makeDecision);
default:
throw ExceptionUtilities.UnexpectedValue(decision.Kind);
}
}
private DecisionTree AddByValue(DecisionTree.Guarded guarded, BoundExpression value, DecisionMaker makeDecision, bool hasErrors)
private DecisionTree AddByValue(DecisionTree.Guarded guarded, BoundExpression value, DecisionMaker makeDecision)
{
if (guarded.Default != null)
{
......@@ -511,20 +511,20 @@ private DecisionTree AddByValue(DecisionTree.Guarded guarded, BoundExpression va
guarded.Default = new DecisionTree.ByValue(guarded.Expression, guarded.Type, null);
}
return AddByValue(guarded.Default, value, makeDecision, hasErrors);
return AddByValue(guarded.Default, value, makeDecision);
}
private DecisionTree AddByValue(DecisionTree.ByValue byValue, BoundExpression value, DecisionMaker makeDecision, bool hasErrors)
private DecisionTree AddByValue(DecisionTree.ByValue byValue, BoundExpression value, DecisionMaker makeDecision)
{
Debug.Assert(value.Type == byValue.Type);
if (byValue.Default != null)
{
return AddByValue(byValue.Default, value, makeDecision, hasErrors);
return AddByValue(byValue.Default, value, makeDecision);
}
// For error recovery, to avoid "unreachable code" diagnostics when there is a bad case
// label, we use the case label itself as the value key.
object valueKey = hasErrors ? (object)value : value.ConstantValue.Value;
object valueKey = value.ConstantValue?.Value ?? value;
DecisionTree valueDecision;
if (byValue.ValueAndDecision.TryGetValue(valueKey, out valueDecision))
{
......@@ -546,13 +546,13 @@ private DecisionTree AddByValue(DecisionTree.ByValue byValue, BoundExpression va
return valueDecision;
}
private DecisionTree AddByValue(DecisionTree.ByType byType, BoundExpression value, DecisionMaker makeDecision, bool hasErrors)
private DecisionTree AddByValue(DecisionTree.ByType byType, BoundExpression value, DecisionMaker makeDecision)
{
if (byType.Default != null)
{
try
{
return AddByValue(byType.Default, value, makeDecision, hasErrors);
return AddByValue(byType.Default, value, makeDecision);
}
finally
{
......@@ -619,7 +619,7 @@ private DecisionTree AddByValue(DecisionTree.ByType byType, BoundExpression valu
byType.TypeAndDecision.Add(new KeyValuePair<TypeSymbol, DecisionTree>(value.Type, forType));
}
return AddByValue(forType, value, makeDecision, hasErrors);
return AddByValue(forType, value, makeDecision);
}
private DecisionTree AddByType(DecisionTree decision, TypeSymbol type, DecisionMaker makeDecision)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册