Skip to content

Commit 90a2b3d

Browse files
committed
Look through "unsafe" expressions when checking for single-value statements
We were rejecting the use of switch expressions on the right-hand side of an assignment that was marked `unsafe`. Fixes rdar://147944753.
1 parent edd118a commit 90a2b3d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/Sema/PreCheckTarget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,11 @@ void PreCheckTarget::markAnyValidSingleValueStmts(Expr *E) {
16801680
while (auto *IIO = dyn_cast<InjectIntoOptionalExpr>(E))
16811681
E = IIO->getSubExpr();
16821682
}
1683+
1684+
// Look through "unsafe" expressions.
1685+
if (auto UE = dyn_cast<UnsafeExpr>(E))
1686+
E = UE->getSubExpr();
1687+
16831688
return dyn_cast<AssignExpr>(E);
16841689
};
16851690

test/Unsafe/safe.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,11 @@ func testMyArray(ints: MyArray<Int>) {
241241
unsafe print(buffer.unsafeCount)
242242
}
243243
}
244+
245+
func testUnsafeLHS() {
246+
@unsafe var value: Int = 0
247+
unsafe value = switch unsafe value {
248+
case 0: 1
249+
default: 0
250+
}
251+
}

0 commit comments

Comments
 (0)