@@ -821,18 +821,11 @@ public func __checkCast<V, T>(
821
821
822
822
// MARK: - Matching errors by type
823
823
824
- /// A placeholder type representing `Never` if a test attempts to instantiate it
825
- /// by calling `#expect(throws:)` and taking the result.
826
- ///
827
- /// Errors of this type are never thrown; they act as placeholders in `Result`
828
- /// so that `#expect(throws: Never.self)` always produces `nil` (since `Never`
829
- /// cannot be instantiated.)
830
- private struct _CannotInstantiateNeverError : Error { }
831
-
832
824
/// Check that an expression always throws an error.
833
825
///
834
826
/// This overload is used for `#expect(throws:) { }` invocations that take error
835
- /// types.
827
+ /// types. It is disfavored so that `#expect(throws: Never.self)` preferentially
828
+ /// returns `Void`.
836
829
///
837
830
/// - Warning: This function is used to implement the `#expect()` and
838
831
/// `#require()` macros. Do not call it directly.
@@ -869,7 +862,8 @@ public func __checkClosureCall<E>(
869
862
/// Check that an expression always throws an error.
870
863
///
871
864
/// This overload is used for `await #expect(throws:) { }` invocations that take
872
- /// error types.
865
+ /// error types. It is disfavored so that `#expect(throws: Never.self)`
866
+ /// preferentially returns `Void`.
873
867
///
874
868
/// - Warning: This function is used to implement the `#expect()` and
875
869
/// `#require()` macros. Do not call it directly.
@@ -923,7 +917,7 @@ public func __checkClosureCall(
923
917
comments: @autoclosure ( ) -> [ Comment ] ,
924
918
isRequired: Bool ,
925
919
sourceLocation: SourceLocation
926
- ) -> Result < Never ? , any Error > {
920
+ ) -> Result < Void , any Error > {
927
921
var success = true
928
922
var mismatchExplanationValue : String ? = nil
929
923
do {
@@ -940,7 +934,7 @@ public func __checkClosureCall(
940
934
comments: comments ( ) ,
941
935
isRequired: isRequired,
942
936
sourceLocation: sourceLocation
943
- ) . map { _ in nil }
937
+ ) . map { _ in }
944
938
}
945
939
946
940
/// Check that an expression never throws an error.
@@ -960,7 +954,7 @@ public func __checkClosureCall(
960
954
isRequired: Bool ,
961
955
isolation: isolated ( any Actor ) ? = #isolation,
962
956
sourceLocation: SourceLocation
963
- ) async -> Result < Never ? , any Error > {
957
+ ) async -> Result < Void , any Error > {
964
958
var success = true
965
959
var mismatchExplanationValue : String ? = nil
966
960
do {
@@ -977,7 +971,7 @@ public func __checkClosureCall(
977
971
comments: comments ( ) ,
978
972
isRequired: isRequired,
979
973
sourceLocation: sourceLocation
980
- ) . map { _ in nil }
974
+ ) . map { _ in }
981
975
}
982
976
983
977
// MARK: - Matching instances of equatable errors
0 commit comments