Skip to content

Commit

Permalink
Use .NET 8.0 UnreachableException where appropriate (#31299)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Jul 18, 2023
1 parent 24e12b4 commit 576590d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override Expression Visit(Expression expression)
}

default:
throw new InvalidOperationException("IMPOSSIBLE");
throw new UnreachableException();
}

var updatedInExpression = inValues.Count > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ or ExpressionType.LessThan
{
ExpressionType.Equal => inExpression,
ExpressionType.NotEqual => _sqlExpressionFactory.Not(inExpression),
_ => throw new InvalidOperationException("IMPOSSIBLE")
_ => throw new UnreachableException()
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,7 @@ SelectExpression subquery
=> subquery.Projection.FirstOrDefault(p => p.Alias == columnExpression.Name) is { Expression.TypeMapping: null },

JoinExpressionBase
=> throw new InvalidOperationException("Impossible: nested join"),
=> throw new UnreachableException("Impossible: nested join"),

// Any other table expression is considered a root (TableValuedFunctionExpression, ValuesExpression...) which *may* be
// untyped, so we record the possible inference (note that TableValuedFunctionExpression may be typed, or not)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ protected override Expression VisitSwitch(SwitchExpression switchExpression)
newInstanceVariable);
break;
default:
throw new InvalidOperationException("IMPOSSIBLE");
throw new UnreachableException();
}

var managerVariable = Variable(typeof(Utf8JsonReaderManager), "jsonReaderManager");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3256,7 +3256,7 @@ or ExpressionType.LessThan
ExpressionType.GreaterThan => ExpressionType.LessThan,
ExpressionType.GreaterThanOrEqual => ExpressionType.LessThanOrEqual,

_ => throw new InvalidOperationException("IMPOSSIBLE")
_ => throw new UnreachableException()
};

return new SqlBinaryExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override void ProcessSinglePropertyJsonUpdate(ref ColumnModificationPa
{
true => "true",
false => "false",
_ => throw new Exception("IMPOSSIBLE")
_ => throw new UnreachableException()
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/Shared/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public static void DebugAssert([DoesNotReturnIf(false)] bool condition, string m
{
if (!condition)
{
throw new Exception($"Check.DebugAssert failed: {message}");
throw new UnreachableException($"Check.DebugAssert failed: {message}");
}
}

[Conditional("DEBUG")]
[DoesNotReturn]
public static void DebugFail(string message)
=> throw new Exception($"Check.DebugFail failed: {message}");
=> throw new UnreachableException($"Check.DebugFail failed: {message}");
}

0 comments on commit 576590d

Please sign in to comment.