fix bug with sum type

pull/3250/head
joe-conigliaro 2019-12-28 18:48:55 +11:00 committed by Alexander Medvednikov
parent 0bdf9bbf4f
commit a214778b74
1 changed files with 10 additions and 8 deletions

View File

@ -51,14 +51,16 @@ fn (p mut Parser) bool_expression() string {
expected = p.expected_type expected = p.expected_type
} }
if expected != typ && expected in p.table.sum_types { // TODO perf 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)
p.cgen.set_placeholder(start_ph, if T.parent == expected {
//'/*SUM TYPE CAST*/($expected) { .obj = &($typ[]) { ') //p.warn('SUM CAST exp=$expected typ=$typ p.exp=$p.expected_type')
'/*SUM TYPE CAST*/($expected) { .obj = memdup(& ') p.cgen.set_placeholder(start_ph,
tt := typ.all_after('_') // TODO //'/*SUM TYPE CAST*/($expected) { .obj = &($typ[]) { ')
//p.gen('}, .typ = SumType_${tt} }')//${val}_type }') '/*SUM TYPE CAST*/($expected) { .obj = memdup(& ')
p.gen(', sizeof($typ) ), .typ = SumType_${tt} }')//${val}_type }') tt := typ.all_after('_') // TODO
//p.gen('}, .typ = SumType_${tt} }')//${val}_type }')
p.gen(', sizeof($typ) ), .typ = SumType_${tt} }')//${val}_type }')
}
} }
return typ return typ
} }