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

cgen: fix struct init; match SumType1, SumType2

This commit is contained in:
Alexander Medvednikov 2020-03-06 14:14:33 +01:00
parent 3de3b38dc1
commit 6b6031a3d9
2 changed files with 40 additions and 30 deletions

View File

@ -555,7 +555,8 @@ fn (g mut Gen) expr(node ast.Expr) {
// `user := User{name: 'Bob'}`
ast.StructInit {
type_sym := g.table.get_type_symbol(it.typ)
g.writeln('($type_sym.name){')
styp := g.typ(type_sym.name)
g.writeln('($styp){')
for i, field in it.fields {
g.write('\t.$field = ')
g.expr(it.exprs[i])

View File

@ -409,6 +409,7 @@ fn (p mut Parser) range_expr(low ast.Expr) ast.Expr {
}
*/
pub fn (p &Parser) error(s string) {
print_backtrace()
mut path := p.file_name
@ -927,6 +928,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
left: left
right: right
// right_type: typ
op: op
pos: pos
}
@ -1037,6 +1039,7 @@ fn (p mut Parser) for_statement() ast.Stmt {
p.scope.register_var(ast.VarDecl{
name: var_name
// expr: cond
})
stmts := p.parse_block()
// println('nr stmts=$stmts.len')
@ -1309,6 +1312,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
fields << ast.Field{
name: name
// typ: typ
}
exprs << expr
// TODO: once consts are fixed reg here & update in checker
@ -1620,6 +1624,11 @@ fn (p mut Parser) match_expr() ast.MatchExpr {
name: 'it'
typ: typ
})
// TODO
if p.tok.kind == .comma {
p.next()
p.parse_type()
}
}
else {
// Expression match