We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
std.optional.value
1 parent 9321007 commit 4e29758Copy full SHA for 4e29758
stdlib/public/Cxx/CxxOptional.swift
@@ -27,8 +27,9 @@ extension CxxOptional {
27
}
28
29
@inlinable
30
- public var value: Wrapped {
+ public var value: Wrapped? {
31
get {
32
+ guard hasValue else { return nil }
33
return pointee
34
35
test/Interop/Cxx/stdlib/use-std-optional.swift
@@ -29,10 +29,11 @@ StdOptionalTestSuite.test("std::optional => Swift.Optional") {
StdOptionalTestSuite.test("std::optional hasValue/value") {
let nonNilOpt = getNonNilOptional()
expectTrue(nonNilOpt.hasValue)
- expectEqual(123, nonNilOpt.value)
+ expectEqual(123, nonNilOpt.value!)
let nilOpt = getNilOptional()
expectFalse(nilOpt.hasValue)
36
+ expectNil(nilOpt.value)
37
38
39
runAllTests()
0 commit comments