mirror of
				https://github.com/golang/go.git
				synced 2025-10-31 08:40:55 +00:00 
			
		
		
		
	cmd/api: fix signatures like func(x, y, z int)
Fixes writing of function parameter, result lists which consist of multiple named or unnamed items with same type. Fixes #4011. R=golang-dev, bsiegert, bradfitz, rsc CC=golang-dev https://golang.org/cl/6475062
This commit is contained in:
		
							parent
							
								
									51e85612f9
								
							
						
					
					
						commit
						1ad5f87635
					
				
					 3 changed files with 32 additions and 3 deletions
				
			
		|  | @ -1017,18 +1017,38 @@ func (w *Walker) walkFuncDecl(f *ast.FuncDecl) { | |||
| 
 | ||||
| func (w *Walker) funcSigString(ft *ast.FuncType) string { | ||||
| 	var b bytes.Buffer | ||||
| 	writeField := func(b *bytes.Buffer, f *ast.Field) { | ||||
| 		if n := len(f.Names); n > 1 { | ||||
| 			for i := 0; i < n; i++ { | ||||
| 				if i > 0 { | ||||
| 					b.WriteString(", ") | ||||
| 				} | ||||
| 				b.WriteString(w.nodeString(w.namelessType(f.Type))) | ||||
| 			} | ||||
| 		} else { | ||||
| 			b.WriteString(w.nodeString(w.namelessType(f.Type))) | ||||
| 		} | ||||
| 	} | ||||
| 	b.WriteByte('(') | ||||
| 	if ft.Params != nil { | ||||
| 		for i, f := range ft.Params.List { | ||||
| 			if i > 0 { | ||||
| 				b.WriteString(", ") | ||||
| 			} | ||||
| 			b.WriteString(w.nodeString(w.namelessType(f.Type))) | ||||
| 			writeField(&b, f) | ||||
| 		} | ||||
| 	} | ||||
| 	b.WriteByte(')') | ||||
| 	if ft.Results != nil { | ||||
| 		if nr := len(ft.Results.List); nr > 0 { | ||||
| 		nr := 0 | ||||
| 		for _, f := range ft.Results.List { | ||||
| 			if n := len(f.Names); n > 1 { | ||||
| 				nr += n | ||||
| 			} else { | ||||
| 				nr++ | ||||
| 			} | ||||
| 		} | ||||
| 		if nr > 0 { | ||||
| 			b.WriteByte(' ') | ||||
| 			if nr > 1 { | ||||
| 				b.WriteByte('(') | ||||
|  | @ -1037,7 +1057,7 @@ func (w *Walker) funcSigString(ft *ast.FuncType) string { | |||
| 				if i > 0 { | ||||
| 					b.WriteString(", ") | ||||
| 				} | ||||
| 				b.WriteString(w.nodeString(w.namelessType(f.Type))) | ||||
| 				writeField(&b, f) | ||||
| 			} | ||||
| 			if nr > 1 { | ||||
| 				b.WriteByte(')') | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mikio Hara
						Mikio Hara