Skip to content

[CSBindings] Overload variable shouldn't be delayed by its application #37835

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

Merged
merged 1 commit into from
Jun 15, 2021
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
13 changes: 12 additions & 1 deletion lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,18 @@ void PotentialBindings::infer(Constraint *constraint) {
}

case ConstraintKind::ApplicableFunction:
case ConstraintKind::DynamicCallableApplicableFunction:
case ConstraintKind::DynamicCallableApplicableFunction: {
auto overloadTy = constraint->getSecondType();
// If current type variable represents an overload set
// being applied to the arguments, it can't be delayed
// by application constraints, because it doesn't
// depend on argument/result types being resolved first.
if (overloadTy->isEqual(TypeVar))
break;

LLVM_FALLTHROUGH;
}

case ConstraintKind::BindOverload: {
DelayedBy.push_back(constraint);
break;
Expand Down
31 changes: 31 additions & 0 deletions test/Constraints/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1132,3 +1132,34 @@ func rdar76058892() {
}
}
}

// rdar://78917861 - Invalid generic type parameter inference

func rdar78917861() {
class Cell {}
class MyCell : Cell {}

class DataCollection<D, C: Cell> {
}

class MyCollection {
typealias DataType = String
typealias CellType = MyCell

var data: DataCollection<DataType, CellType>

init() {
self.data = DataCollection<DataType, CellType>()
}
}

class Test {
let collection = MyCollection()

lazy var prop: DataCollection = {
collection.data // Ok
// Since contextual type `DataCollection` doesn't specify generic parameters they have to be inferred
// but that has to wait until the closure is resolved because types can flow both ways
}()
}
}