Skip to content

Commit 6ceb9c1

Browse files
authored
Merge pull request #80634 from hamishknight/lifetime-variance
[Sema] Ignore types with type variables in `filterEscapableLifetimeDependencies`
2 parents 1b5a94e + 9114aad commit 6ceb9c1

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
@@ -87,7 +87,12 @@ filterEscapableLifetimeDependencies(GenericSignature sig,
8787
for (auto &depInfo : inputs) {
8888
auto targetIndex = depInfo.getTargetIndex();
8989
Type substTy = getSubstTargetType(targetIndex);
90-
90+
91+
// If the type still contains type variables we don't know whether we
92+
// can drop the dependency.
93+
if (substTy->hasTypeVariable())
94+
continue;
95+
9196
// Drop the dependency if the target type is Escapable.
9297
if (sig || !substTy->hasTypeParameter()) {
9398
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)