Skip to content

Commit bda01a7

Browse files
Merge pull request swiftlang#58740 from LucianoPAlmeida/hole-opt-try
[Sema] Limit optional type variable hole propagation only to OptionalEvaluationExpr binding
2 parents 192298b + 6ddd31f commit bda01a7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,8 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
19931993
// without any contextual information, so even though `x` would get
19941994
// bound to result type of the chain, underlying type variable wouldn't
19951995
// be resolved, so we need to propagate holes up the conversion chain.
1996-
if (TypeVar->getImpl().canBindToHole()) {
1996+
if (TypeVar->getImpl().canBindToHole() &&
1997+
srcLocator->directlyAt<OptionalEvaluationExpr>()) {
19971998
if (auto objectTy = type->getOptionalObjectType()) {
19981999
if (auto *typeVar = objectTy->getAs<TypeVariableType>())
19992000
cs.recordPotentialHole(typeVar);

test/Constraints/optional.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,6 @@ func rdar85166519() {
509509
v?.addingReportingOverflow(0) // expected-error {{cannot convert value of type '(partialValue: Int, overflow: Bool)?' to expected dictionary key type 'Int'}}
510510
]
511511
}
512+
513+
// https://github.com/apple/swift/issues/58539
514+
if let x = nil {} // expected-error{{'nil' requires a contextual type}}

test/Constraints/try_swift5.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 5
2+
3+
// https://github.com/apple/swift/issues/58661
4+
class I58661 {
5+
func throwing<T>() throws -> T { // expected-note{{in call to function 'throwing()'}}
6+
throw Swift.fatalError()
7+
}
8+
9+
func reproduce() {
10+
let check = try? throwing() // expected-error{{generic parameter 'T' could not be inferred}}
11+
}
12+
}

0 commit comments

Comments
 (0)