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

js: add initial support for optional types, IfGuardExpr codegen for if (#11332)

This commit is contained in:
playX
2021-08-29 14:27:17 +03:00
committed by GitHub
parent 985fe85de2
commit 61ac7b671d
3 changed files with 200 additions and 63 deletions

View File

@ -19,11 +19,6 @@ pub fn panic(s string) {
exit(1)
}
struct Option {
state byte
err Error
}
// IError holds information about an error instance
pub interface IError {
msg string
@ -37,7 +32,12 @@ pub:
code int
}
const none__ = IError(&None__{})
pub const none__ = IError(&None__{})
pub struct Option {
state byte
err IError = none__
}
struct None__ {
msg string
@ -66,7 +66,6 @@ pub fn (o Option) str() string {
return 'Option{ error: "$o.err" }'
}
[if trace_error ?]
fn trace_error(x string) {
eprintln('> ${@FN} | $x')
}
@ -75,7 +74,7 @@ fn trace_error(x string) {
// Example: `if ouch { return error('an error occurred') }`
[inline]
pub fn error(message string) IError {
trace_error(message)
// trace_error(message)
return &Error{
msg: message
}