vfmt2: skip arg type if possible
							parent
							
								
									c314ab7b60
								
							
						
					
					
						commit
						39c4842bf9
					
				|  | @ -29,7 +29,7 @@ pub fn fmt(file ast.File, table &table.Table) string { | |||
| 		indent: -1 | ||||
| 	} | ||||
| 	f.stmts(file.stmts) | ||||
| 	return f.out.str() | ||||
| 	return f.out.str().trim_space() + '\n' | ||||
| } | ||||
| 
 | ||||
| pub fn (f mut Fmt) write(s string) { | ||||
|  | @ -106,9 +106,14 @@ fn (f mut Fmt) stmt(node ast.Stmt) { | |||
| 			} | ||||
| 			f.write('fn ${receiver}${it.name}(') | ||||
| 			for i, arg in it.args { | ||||
| 				sym := f.table.get_type_symbol(arg.typ) | ||||
| 				f.write('$arg.name $sym.name') | ||||
| 				if i < it.args.len - 1 { | ||||
| 				is_last_arg := i == it.args.len - 1 | ||||
| 				should_add_type := is_last_arg || it.args[i + 1].typ != arg.typ | ||||
| 				f.write(arg.name) | ||||
| 				if should_add_type { | ||||
| 					arg_typ_sym := f.table.get_type_symbol(arg.typ) | ||||
| 					f.write(' ${arg_typ_sym.name}') | ||||
| 				} | ||||
| 				if !is_last_arg { | ||||
| 					f.write(', ') | ||||
| 				} | ||||
| 			} | ||||
|  |  | |||
|  | @ -45,3 +45,26 @@ fn voidfn() { | |||
| 	println('this is a function that does not return anything') | ||||
| } | ||||
| 
 | ||||
| fn fn_with_1_arg(arg int) int { | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_2a_args(arg1, arg2 int) int { | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_2_args_to_be_shorten(arg1, arg2 int) int { | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_2b_args(arg1 string, arg2 int) int { | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_3_args(arg1 string, arg2 int, arg3 User) int { | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| fn (this User) fn_with_receiver() { | ||||
| 	println('') | ||||
| } | ||||
|  |  | |||
|  | @ -48,3 +48,27 @@ User | |||
| fn   voidfn(){ | ||||
|  println('this is a function that does not return anything') | ||||
|    } | ||||
| 
 | ||||
| fn fn_with_1_arg(arg int) int { | ||||
| return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_2a_args(arg1, arg2 int) int { | ||||
| return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_2_args_to_be_shorten(arg1 int, arg2 int) int { | ||||
| return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_2b_args(arg1 string, arg2 int) int { | ||||
| return 0 | ||||
| } | ||||
| 
 | ||||
| fn fn_with_3_args(arg1 string, arg2 int, arg3 User) int { | ||||
| return 0 | ||||
| } | ||||
| 
 | ||||
| fn    (this User) fn_with_receiver() { | ||||
| println('') | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue