parser, checker: cleanup struct short syntax processing (#13416)

pull/13419/head
yuyi 2022-02-10 00:31:16 +08:00 committed by GitHub
parent 0d1d259bb4
commit f2eb50008d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 4 deletions

View File

@ -116,7 +116,7 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
if node.typ == ast.void_type {
// Short syntax `({foo: bar})`
// short syntax `foo(key:val, key2:val2)`
if c.expected_type == ast.void_type {
c.error('unexpected short struct syntax', node.pos)
return ast.void_type

View File

@ -126,7 +126,7 @@ pub fn (mut p Parser) call_args() []ast.CallArg {
mut expr := ast.empty_expr()
if p.tok.kind == .name && p.peek_tok.kind == .colon {
// `foo(key:val, key2:val2)`
expr = p.struct_init(p.mod + '.' + p.tok.lit, true) // short_syntax:true
expr = p.struct_init('void_type', true) // short_syntax:true
} else {
expr = p.expr(0)
}

View File

@ -340,8 +340,6 @@ fn (mut p Parser) struct_init(typ_str string, short_syntax bool) ast.StructInit
p.struct_init_generic_types = []ast.Type{}
typ := if short_syntax { ast.void_type } else { p.parse_type() }
p.expr_mod = ''
// sym := p.table.sym(typ)
// p.warn('struct init typ=$sym.name')
if !short_syntax {
p.check(.lcbr)
}