Skip to content

Commit dc70a0e

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. This is incorrect; the type variables come up in ValueWitnessRequest, and the type parameters come up in associated type inference. We want the matching to be more lax in the former case. Fixes rdar://149438520.
1 parent 7e59265 commit dc70a0e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Sema/TypeCheckProtocol.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,7 @@ RequirementMatch swift::matchWitness(
912912

913913
case ThrownErrorSubtyping::Subtype:
914914
// If there were no type parameters, we're done.
915-
if (!reqThrownError->hasTypeVariable() &&
916-
!reqThrownError->hasTypeParameter())
915+
if (!reqThrownError->hasTypeParameter())
917916
break;
918917

919918
LLVM_FALLTHROUGH;

test/decl/protocol/conforms/typed_throws.swift

+14
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)