vfmt: support `x := chan Name{cap: 123}`
							parent
							
								
									1d39116a6e
								
							
						
					
					
						commit
						8f5ca29fcd
					
				| 
						 | 
				
			
			@ -804,14 +804,7 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
 | 
			
		|||
			f.call_expr(node)
 | 
			
		||||
		}
 | 
			
		||||
		ast.ChanInit {
 | 
			
		||||
			f.write('chan[')
 | 
			
		||||
			f.write(f.type_to_str(node.elem_type))
 | 
			
		||||
			f.write(']{')
 | 
			
		||||
			if node.has_cap {
 | 
			
		||||
				f.write('cap: ')
 | 
			
		||||
				f.expr(node.cap_expr)
 | 
			
		||||
			}
 | 
			
		||||
			f.write('}')
 | 
			
		||||
			f.chan_init(mut node)
 | 
			
		||||
		}
 | 
			
		||||
		ast.CharLiteral {
 | 
			
		||||
			f.write('`$node.val`')
 | 
			
		||||
| 
						 | 
				
			
			@ -1623,6 +1616,21 @@ fn expr_is_single_line(expr ast.Expr) bool {
 | 
			
		|||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn (mut f Fmt) chan_init(mut it ast.ChanInit) {
 | 
			
		||||
	if it.elem_type == 0 && it.typ > 0 {
 | 
			
		||||
		info := f.table.get_type_symbol(it.typ).chan_info()
 | 
			
		||||
		it.elem_type = info.elem_type
 | 
			
		||||
	}
 | 
			
		||||
	f.write('chan ')
 | 
			
		||||
	f.write(f.type_to_str(it.elem_type))
 | 
			
		||||
	f.write('{')
 | 
			
		||||
	if it.has_cap {
 | 
			
		||||
		f.write('cap: ')
 | 
			
		||||
		f.expr(it.cap_expr)
 | 
			
		||||
	}
 | 
			
		||||
	f.write('}')
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
 | 
			
		||||
	if it.exprs.len == 0 && it.typ != 0 && it.typ != table.void_type {
 | 
			
		||||
		// `x := []string`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
import sync
 | 
			
		||||
 | 
			
		||||
struct FSMEvent {
 | 
			
		||||
	x int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
	ch_fsm_events := chan FSMEvent{cap: 1000}
 | 
			
		||||
	eprintln('ch_fsm_events.len: $ch_fsm_events.len')
 | 
			
		||||
	eprintln('ch_fsm_events.cap: $ch_fsm_events.cap')
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue