mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +03:00
compiler: implement direct cast for sum type
This commit is contained in:
parent
520ec0f53a
commit
43895269ff
2 changed files with 19 additions and 4 deletions
|
@ -28,12 +28,12 @@ struct BoolExpr {
|
|||
}
|
||||
|
||||
struct BinExpr {
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
fn expr1() Expr {
|
||||
mut e := Expr{}
|
||||
e = BinExpr{}
|
||||
e = BinExpr{'binexpr'}
|
||||
return e
|
||||
//return BinExpr{}
|
||||
}
|
||||
|
@ -55,6 +55,12 @@ fn parse_bool() BoolExpr {
|
|||
return BoolExpr{}
|
||||
}
|
||||
|
||||
fn test_sum_type_cast() {
|
||||
a := expr1()
|
||||
b := a as BinExpr
|
||||
assert b.name == 'binexpr'
|
||||
}
|
||||
|
||||
fn test_sum_types() {
|
||||
b := parse_bool()
|
||||
handle_expr(b)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue