Skip to content

[6.2] Sema: Fix case where witness thrown error type is a subtype of a type parameter #80965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,17 +907,10 @@ RequirementMatch swift::matchWitness(
return RequirementMatch(witness, MatchKind::ThrowsConflict);

case ThrownErrorSubtyping::ExactMatch:
case ThrownErrorSubtyping::Subtype:
// All is well.
break;

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

LLVM_FALLTHROUGH;

case ThrownErrorSubtyping::Dependent:
// We need to perform type matching
if (auto result = matchTypes(reqThrownError, witnessThrownError)) {
Expand Down
14 changes: 14 additions & 0 deletions test/decl/protocol/conforms/typed_throws.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ public protocol HasRethrowingMap: Sequence {
}

extension Array: HasRethrowingMap {}

// rdar://149438520 -- incorrect handling of subtype relation between type parameter and Never
protocol DependentThrowing {
associatedtype E: Error
func f() throws(E)
}

extension DependentThrowing {
func f() {}
}

struct DefaultDependentThrowing: DependentThrowing {
typealias E = Error
}