Skip to content

Commit 49901c2

Browse files
committed
Sema: Fix case where witness thrown error type is a subtype of a type parameter
In b300068, I changed the `if` condition here to check for the absence of type variables as well as type parameters. The correct condition is to actually not check for anything at all. Fixes rdar://149438520.
1 parent cdc02a4 commit 49901c2

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -907,17 +907,10 @@ RequirementMatch swift::matchWitness(
907907
return RequirementMatch(witness, MatchKind::ThrowsConflict);
908908

909909
case ThrownErrorSubtyping::ExactMatch:
910+
case ThrownErrorSubtyping::Subtype:
910911
// All is well.
911912
break;
912913

913-
case ThrownErrorSubtyping::Subtype:
914-
// If there were no type parameters, we're done.
915-
if (!reqThrownError->hasTypeVariable() &&
916-
!reqThrownError->hasTypeParameter())
917-
break;
918-
919-
LLVM_FALLTHROUGH;
920-
921914
case ThrownErrorSubtyping::Dependent:
922915
// We need to perform type matching
923916
if (auto result = matchTypes(reqThrownError, witnessThrownError)) {

test/decl/protocol/conforms/typed_throws.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,17 @@ public protocol HasRethrowingMap: Sequence {
7777
}
7878

7979
extension Array: HasRethrowingMap {}
80+
81+
// rdar://149438520 -- incorrect handling of subtype relation between type parameter and Never
82+
protocol DependentThrowing {
83+
associatedtype E: Error
84+
func f() throws(E)
85+
}
86+
87+
extension DependentThrowing {
88+
func f() {}
89+
}
90+
91+
struct DefaultDependentThrowing: DependentThrowing {
92+
typealias E = Error
93+
}

0 commit comments

Comments
 (0)