Skip to content

Commit 87f9dcb

Browse files
committed
[Sema] Ignore types with type variables in filterEscapableLifetimeDependencies
If the type still has type variables, avoid trying to check if it's escapable. rdar://148749815
1 parent ead547d commit 87f9dcb

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ filterEscapableLifetimeDependencies(GenericSignature sig,
5858
for (auto &depInfo : inputs) {
5959
auto targetIndex = depInfo.getTargetIndex();
6060
Type substTy = getSubstTargetType(targetIndex);
61-
61+
62+
// If the type still contains type variables we don't know whether we
63+
// can drop the dependency.
64+
if (substTy->hasTypeVariable())
65+
continue;
66+
6267
// Drop the dependency if the target type is Escapable.
6368
if (sig || !substTy->hasTypeParameter()) {
6469
if (substTy->isEscapable(sig)) {

test/IDE/issue-80591.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %batch-code-completion -enable-experimental-feature LifetimeDependence
2+
3+
// REQUIRES: swift_feature_LifetimeDependence
4+
5+
infix operator ^^^
6+
7+
extension Optional where Wrapped: ~Escapable & ~Copyable {
8+
@lifetime(copy self) mutating func foo() -> Self { fatalError() }
9+
}
10+
11+
func ^^^ <T: ~Escapable & ~Copyable> (_ x: Int, _ y: borrowing T?) {}
12+
13+
// https://github.com/swiftlang/swift/issues/80591 - Make sure we don't crash
14+
// here.
15+
func foo() {
16+
_ = 1 ^^^ .#^COMPLETE^#
17+
// COMPLETE: Decl[InstanceMethod]/CurrNominal/TypeRelation[Convertible]: foo({#(self): &Optional<~Copyable & ~Escapable>#})[#() -> Optional<~Copyable & ~Escapable>#]; name=foo(:)
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %batch-code-completion
2+
3+
// https://github.com/apple/swift/issues/80591
4+
5+
// Just make sure we don't crash.
6+
var foo: Bool {
7+
baz == .#^COMPLETE^#
8+
// COMPLETE: Begin completions
9+
}

0 commit comments

Comments
 (0)