parser, checker: cleanup struct short syntax processing (#13416)
							parent
							
								
									0d1d259bb4
								
							
						
					
					
						commit
						f2eb50008d
					
				|  | @ -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 { | pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { | ||||||
| 	if node.typ == ast.void_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 { | 		if c.expected_type == ast.void_type { | ||||||
| 			c.error('unexpected short struct syntax', node.pos) | 			c.error('unexpected short struct syntax', node.pos) | ||||||
| 			return ast.void_type | 			return ast.void_type | ||||||
|  |  | ||||||
|  | @ -126,7 +126,7 @@ pub fn (mut p Parser) call_args() []ast.CallArg { | ||||||
| 		mut expr := ast.empty_expr() | 		mut expr := ast.empty_expr() | ||||||
| 		if p.tok.kind == .name && p.peek_tok.kind == .colon { | 		if p.tok.kind == .name && p.peek_tok.kind == .colon { | ||||||
| 			// `foo(key:val, key2:val2)`
 | 			// `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 { | 		} else { | ||||||
| 			expr = p.expr(0) | 			expr = p.expr(0) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -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{} | 	p.struct_init_generic_types = []ast.Type{} | ||||||
| 	typ := if short_syntax { ast.void_type } else { p.parse_type() } | 	typ := if short_syntax { ast.void_type } else { p.parse_type() } | ||||||
| 	p.expr_mod = '' | 	p.expr_mod = '' | ||||||
| 	// sym := p.table.sym(typ)
 |  | ||||||
| 	// p.warn('struct init typ=$sym.name')
 |  | ||||||
| 	if !short_syntax { | 	if !short_syntax { | ||||||
| 		p.check(.lcbr) | 		p.check(.lcbr) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue