Skip to content

Commit 0295e04

Browse files
authored
Merge pull request #21638 from DougGregor/unowned-optional-let
[Type checker] Allow unowned/unowned(unsafe) optional lets.
2 parents 3275f56 + 7ea7d32 commit 0295e04

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,9 +2413,7 @@ void TypeChecker::checkReferenceOwnershipAttr(VarDecl *var,
24132413
}
24142414
break;
24152415
case ReferenceOwnershipOptionality::Allowed:
2416-
if (!isOptional)
2417-
break;
2418-
LLVM_FALLTHROUGH;
2416+
break;
24192417
case ReferenceOwnershipOptionality::Required:
24202418
if (var->isLet()) {
24212419
diagnose(var->getStartLoc(), diag::invalid_ownership_is_let,

test/attr/attributes.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,12 @@ class HasStorage {
273273
@_invalid_attribute_ // expected-error {{unknown attribute '_invalid_attribute_'}}
274274
@inline(__always)
275275
public func sillyFunction() {}
276+
277+
// rdar://problem/45732251: unowned/unowned(unsafe) optional lets are permitted
278+
func unownedOptionals(x: C) {
279+
unowned let y: C? = x
280+
unowned(unsafe) let y2: C? = x
281+
282+
_ = y
283+
_ = y2
284+
}

0 commit comments

Comments
 (0)