[Sema] Limit optional type variable hole propagation only to OptionalEvaluationExpr binding

This commit is contained in:
Luciano Almeida
2022-05-07 19:37:24 -03:00
parent 261953a43b
commit 984159384d
2 changed files with 14 additions and 1 deletions

View File

@@ -1993,7 +1993,8 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
// without any contextual information, so even though `x` would get
// bound to result type of the chain, underlying type variable wouldn't
// be resolved, so we need to propagate holes up the conversion chain.
if (TypeVar->getImpl().canBindToHole()) {
if (TypeVar->getImpl().canBindToHole() &&
srcLocator->directlyAt<OptionalEvaluationExpr>()) {
if (auto objectTy = type->getOptionalObjectType()) {
if (auto *typeVar = objectTy->getAs<TypeVariableType>())
cs.recordPotentialHole(typeVar);

View File

@@ -0,0 +1,12 @@
// RUN: %target-typecheck-verify-swift -swift-version 5
// https://github.com/apple/swift/issues/58661
class I58661 {
func throwing<T>() throws -> T { // expected-note{{in call to function 'throwing()'}}
throw Swift.fatalError()
}
func reproduce() {
let check = try? throwing() // expected-error{{generic parameter 'T' could not be inferred}}
}
}