Skip to content

Commit a15f8fd

Browse files
committed
Fix generic initializers with lifetime dependence
1 parent bb530de commit a15f8fd

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class AnyFunctionRef {
118118
return FD->mapTypeIntoContext(FD->getResultInterfaceType());
119119
if (auto *CD = dyn_cast<ConstructorDecl>(AFD)) {
120120
if (CD->hasLifetimeDependentReturn()) {
121-
return CD->getResultInterfaceType();
121+
return CD->mapTypeIntoContext(CD->getResultInterfaceType());
122122
}
123123
}
124124
return TupleType::getEmpty(AFD->getASTContext());

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,7 @@ class Verifier : public ASTWalker {
10781078
} else if (auto *CD = dyn_cast<ConstructorDecl>(func)) {
10791079
if (CD->hasLifetimeDependentReturn()) {
10801080
resultType = CD->getResultInterfaceType();
1081+
resultType = CD->mapTypeIntoContext(resultType);
10811082
} else {
10821083
resultType = TupleType::getEmpty(Ctx);
10831084
}

test/Sema/explicit_lifetime_dependence_specifiers.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,27 @@ struct Wrapper : ~Escapable {
137137
return view
138138
}
139139
}
140+
141+
public struct GenericBufferView<Element> : ~Escapable {
142+
public typealias Index = Int
143+
public typealias Pointer = UnsafePointer<Element>
144+
145+
public let baseAddress: Pointer
146+
public let count: Int
147+
148+
public init<Storage>(unsafeBuffer: UnsafeBufferPointer<Element>,
149+
storage: borrowing Storage)
150+
-> _borrow(storage) Self {
151+
let baseAddress = unsafeBuffer.baseAddress!
152+
self = GenericBufferView<Element>(baseAddress: baseAddress,
153+
count: unsafeBuffer.count)
154+
return self
155+
}
156+
// unsafe private API
157+
@_unsafeNonescapableResult
158+
init(baseAddress: Pointer, count: Int) {
159+
precondition(count >= 0, "Count must not be negative")
160+
self.baseAddress = baseAddress
161+
self.count = count
162+
}
163+
}

0 commit comments

Comments
 (0)