Skip to content

Commit afb1404

Browse files
Merge pull request #58776 from LucianoPAlmeida/hole-try-5-7
[5.7][Sema] Limit optional type variable hole propagation only to OptionalEvaluationExpr binding
2 parents 177515f + 89a8e2d commit afb1404

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,10 +1993,16 @@ 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+
// Also propagate in code completion mode because in some cases code
1997+
// completion relies on type variable being a potential hole.
19961998
if (TypeVar->getImpl().canBindToHole()) {
1997-
if (auto objectTy = type->getOptionalObjectType()) {
1998-
if (auto *typeVar = objectTy->getAs<TypeVariableType>())
1999-
cs.recordPotentialHole(typeVar);
1999+
if (srcLocator->directlyAt<OptionalEvaluationExpr>() ||
2000+
cs.isForCodeCompletion()) {
2001+
if (auto objectTy = type->getOptionalObjectType()) {
2002+
if (auto *typeVar = objectTy->getAs<TypeVariableType>()) {
2003+
cs.recordPotentialHole(typeVar);
2004+
}
2005+
}
20002006
}
20012007
}
20022008

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+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token COMPLETE | %FileCheck %s
2+
3+
struct Foo {
4+
var x: Int = {
5+
guard let foo = #^COMPLETE^#
6+
}()
7+
}
8+
9+
// CHECK: Decl[Struct]/CurrModule: Foo[#Foo#];

0 commit comments

Comments
 (0)