Skip to content
Merged
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
14 changes: 11 additions & 3 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,17 @@ Optional<SelectedOverload> FailureDiagnostic::getChoiceFor(Expr *expr) const {
}

Type RequirementFailure::getOwnerType() const {
return getType(getRawAnchor())
->getInOutObjectType()
->getMetatypeInstanceType();
auto *anchor = getRawAnchor();

// If diagnostic is anchored at assignment expression
// it means that requirement failure happend while trying
// to convert source to destination, which means that
// owner type is actually not an assignment expression
// itself but its source.
if (auto *assignment = dyn_cast<AssignExpr>(anchor))
anchor = assignment->getSrc();

return getType(anchor)->getInOutObjectType()->getMetatypeInstanceType();
}

const GenericContext *RequirementFailure::getGenericContext() const {
Expand Down
24 changes: 24 additions & 0 deletions test/Constraints/sr10906.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %target-typecheck-verify-swift

protocol ViewDataSource: class {
func foo<T>() -> [T]
}

class View {
weak var delegate: ViewDataSource?
}

final class ViewController<T> {
let view = View()
init() {
view.delegate = self
// expected-error@-1 {{generic class 'ViewController' requires the types 'T' and 'String' be equivalent}}
}
}

extension ViewController: ViewDataSource where T == String {
// expected-note@-1 {{requirement from conditional conformance of 'ViewController<T>' to 'ViewDataSource'}}
func foo<T>() -> [T] {
return []
}
}