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

js: fix printing, make builtins for result and option types behave correctly (#11336)

This commit is contained in:
playX
2021-08-30 20:47:18 +03:00
committed by GitHub
parent f33f216698
commit a9b705bfd8
6 changed files with 382 additions and 244 deletions

View File

@@ -6,14 +6,6 @@ module builtin
fn (a any) toString()
pub fn unwrap(opt any) any {
o := &Option(opt)
if o.state != 0 {
js_throw(o.err)
}
return opt
}
pub fn panic(s string) {
eprintln('V panic: $s')
exit(1)
@@ -32,13 +24,6 @@ pub:
code int
}
pub const none__ = IError(&None__{})
pub struct Option {
state byte
err IError = none__
}
struct None__ {
msg string
code int
@@ -48,6 +33,13 @@ fn (_ None__) str() string {
return 'none'
}
pub const none__ = IError(None__{'', 0})
pub struct Option {
state byte
err IError = none__
}
pub fn (err IError) str() string {
return match err {
None__ { 'none' }