1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: add none str() (fix #12964) (#12967)

This commit is contained in:
yuyi 2021-12-26 17:41:51 +08:00 committed by GitHub
parent 03864e4ab8
commit 3b5de71e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -87,3 +87,7 @@ pub fn (e &Error) free() {
pub fn (n &None__) free() {
unsafe { n.msg.free() }
}
pub fn (_ none) str() string {
return 'none'
}

View File

@ -0,0 +1,14 @@
struct MyError {
code int
msg string
}
fn foo() int | none | IError {
return IError(MyError{})
}
fn test_string_optional_none() {
x := foo()
println(x)
assert true
}