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

staments + a sum type fix

This commit is contained in:
Alexander Medvednikov
2019-12-28 14:11:05 +01:00
parent 68e1d8e8eb
commit b5fe40624c
9 changed files with 244 additions and 157 deletions

View File

@ -47,19 +47,17 @@ fn (p mut Parser) bool_expression() string {
println(tok.str())
p.error('expr() returns empty type')
}
if p.inside_return_expr { //is_ret { // return a,b hack TODO
if p.inside_return_expr && p.expected_type.contains('_MulRet_') { //is_ret { // return a,b hack TODO
expected = p.expected_type
}
if expected != typ && expected in p.table.sum_types { // TODO perf
//p.warn('SUM CAST exp=$expected typ=$typ p.exp=$p.expected_type')
T := p.table.find_type(typ)
if T.parent == expected {
//p.warn('SUM CAST exp=$expected typ=$typ p.exp=$p.expected_type')
p.cgen.set_placeholder(start_ph,
//'/*SUM TYPE CAST*/($expected) { .obj = &($typ[]) { ')
'/*SUM TYPE CAST*/($expected) { .obj = memdup(& ')
'/*SUM TYPE CAST2*/($expected) { .obj = memdup( &($typ[]) { ')
tt := typ.all_after('_') // TODO
//p.gen('}, .typ = SumType_${tt} }')//${val}_type }')
p.gen(', sizeof($typ) ), .typ = SumType_${tt} }')//${val}_type }')
p.gen('}, sizeof($typ) ), .typ = SumType_${tt} }')//${val}_type }')
}
}
return typ

View File

@ -31,6 +31,17 @@ struct BinExpr {
}
fn expr1() Expr {
mut e := Expr{}
e = BinExpr{}
return e
//return BinExpr{}
}
fn expr2() Expr {
return BinExpr{}
}
struct UnaryExpr {
}