diff --git a/vlib/builtin/option.v b/vlib/builtin/option.v index 1f1bdd9b61..cc1a5a3149 100644 --- a/vlib/builtin/option.v +++ b/vlib/builtin/option.v @@ -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' +} diff --git a/vlib/v/tests/string_optional_none_test.v b/vlib/v/tests/string_optional_none_test.v new file mode 100644 index 0000000000..c71cc00c6d --- /dev/null +++ b/vlib/v/tests/string_optional_none_test.v @@ -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 +}