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

sum type type Foo = Bar | Baz

This commit is contained in:
Alexander Medvednikov
2019-12-24 11:07:26 +03:00
parent 9dd05474b0
commit 803ded3dec
4 changed files with 137 additions and 12 deletions

View File

@ -4,6 +4,8 @@
module compiler
fn (p mut Parser) bool_expression() string {
start_ph := p.cgen.add_placeholder()
expected := p.expected_type
tok := p.tok
typ := p.bterm()
mut got_and := false // to catch `a && b || c` in one expression without ()
@ -44,6 +46,11 @@ fn (p mut Parser) bool_expression() string {
println(tok.str())
p.error('expr() returns empty type')
}
if expected != typ && expected in p.table.sum_types { // TODO perf
p.cgen.set_placeholder(start_ph, '/*KUK*/($expected) { .obj = ($typ[]) { ')
p.gen('}, .typ = 1}')//${val}_type }')
}
return typ
}
@ -362,7 +369,7 @@ fn (p mut Parser) name_expr() string {
//println(q)
//println(q[idx])
arg_type := q[idx]
p.gen('($enum_type.name) { .obj = ($arg_type[]) { ')
p.gen('($enum_type.name) { .obj = ($arg_type[]) { ')
p.bool_expression()
p.check(.rpar)
p.gen('}, .typ = ${val}_type }')