Skip to content

Commit 6923717

Browse files
authored
Merge pull request #65944 from apple/egorzhdan/5.9-cxx-optional-nullable-value
🍒[cxx-interop] Make `std.optional.value` nullable
2 parents 310ff65 + 6c9d141 commit 6923717

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

stdlib/public/Cxx/CxxOptional.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ extension CxxOptional {
2727
}
2828

2929
@inlinable
30-
public var value: Wrapped {
30+
public var value: Wrapped? {
3131
get {
32+
guard hasValue else { return nil }
3233
return pointee
3334
}
3435
}

test/Interop/Cxx/stdlib/use-std-optional.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ StdOptionalTestSuite.test("std::optional => Swift.Optional") {
2929
StdOptionalTestSuite.test("std::optional hasValue/value") {
3030
let nonNilOpt = getNonNilOptional()
3131
expectTrue(nonNilOpt.hasValue)
32-
expectEqual(123, nonNilOpt.value)
32+
expectEqual(123, nonNilOpt.value!)
3333

3434
let nilOpt = getNilOptional()
3535
expectFalse(nilOpt.hasValue)
36+
expectNil(nilOpt.value)
3637
}
3738

3839
runAllTests()

0 commit comments

Comments
 (0)