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:
parent
3de3b38dc1
commit
6b6031a3d9
@ -555,7 +555,8 @@ fn (g mut Gen) expr(node ast.Expr) {
|
|||||||
// `user := User{name: 'Bob'}`
|
// `user := User{name: 'Bob'}`
|
||||||
ast.StructInit {
|
ast.StructInit {
|
||||||
type_sym := g.table.get_type_symbol(it.typ)
|
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 {
|
for i, field in it.fields {
|
||||||
g.write('\t.$field = ')
|
g.write('\t.$field = ')
|
||||||
g.expr(it.exprs[i])
|
g.expr(it.exprs[i])
|
||||||
|
@ -409,6 +409,7 @@ fn (p mut Parser) range_expr(low ast.Expr) ast.Expr {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
pub fn (p &Parser) error(s string) {
|
pub fn (p &Parser) error(s string) {
|
||||||
print_backtrace()
|
print_backtrace()
|
||||||
mut path := p.file_name
|
mut path := p.file_name
|
||||||
@ -927,6 +928,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
|
|||||||
left: left
|
left: left
|
||||||
right: right
|
right: right
|
||||||
// right_type: typ
|
// right_type: typ
|
||||||
|
|
||||||
op: op
|
op: op
|
||||||
pos: pos
|
pos: pos
|
||||||
}
|
}
|
||||||
@ -1037,6 +1039,7 @@ fn (p mut Parser) for_statement() ast.Stmt {
|
|||||||
p.scope.register_var(ast.VarDecl{
|
p.scope.register_var(ast.VarDecl{
|
||||||
name: var_name
|
name: var_name
|
||||||
// expr: cond
|
// expr: cond
|
||||||
|
|
||||||
})
|
})
|
||||||
stmts := p.parse_block()
|
stmts := p.parse_block()
|
||||||
// println('nr stmts=$stmts.len')
|
// println('nr stmts=$stmts.len')
|
||||||
@ -1309,6 +1312,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
|
|||||||
fields << ast.Field{
|
fields << ast.Field{
|
||||||
name: name
|
name: name
|
||||||
// typ: typ
|
// typ: typ
|
||||||
|
|
||||||
}
|
}
|
||||||
exprs << expr
|
exprs << expr
|
||||||
// TODO: once consts are fixed reg here & update in checker
|
// TODO: once consts are fixed reg here & update in checker
|
||||||
@ -1620,6 +1624,11 @@ fn (p mut Parser) match_expr() ast.MatchExpr {
|
|||||||
name: 'it'
|
name: 'it'
|
||||||
typ: typ
|
typ: typ
|
||||||
})
|
})
|
||||||
|
// TODO
|
||||||
|
if p.tok.kind == .comma {
|
||||||
|
p.next()
|
||||||
|
p.parse_type()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Expression match
|
// Expression match
|
||||||
|
Loading…
Reference in New Issue
Block a user