-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dev.typeparams] cmd/gofmt: add the -G flag to allow generic code
Add support for type parameters to cmd/gofmt, gated behind the -G flag. The test was based on a test from go/printer, slightly modified to exercise more formatting. Change-Id: I489bcb3ad06e1ed4e6d9f5bc79825e60dcfe9953 Reviewed-on: https://go-review.googlesource.com/c/go/+/291011 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
- Loading branch information
Showing
5 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//gofmt -G | ||
|
||
package typeparams | ||
|
||
type T[P any] struct{} | ||
type T[P1, P2, P3 any] struct{} | ||
|
||
type T[P C] struct{} | ||
type T[P1, P2, P3 C] struct{} | ||
|
||
type T[P C[P]] struct{} | ||
type T[P1, P2, P3 C[P1, P2, P3]] struct{} | ||
|
||
func f[P any](x P) | ||
func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{} | ||
|
||
func f[P interface{}](x P) | ||
func f[P1, P2, P3 interface { | ||
m1(P1) | ||
type P2, P3 | ||
}](x1 P1, x2 P2, x3 P3) struct{} | ||
func f[P any](T1[P], T2[P]) T3[P] | ||
|
||
func (x T[P]) m() | ||
func (T[P]) m(x T[P]) P | ||
|
||
func _() { | ||
type _ []T[P] | ||
var _ []T[P] | ||
_ = []T[P]{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//gofmt -G | ||
|
||
package typeparams | ||
|
||
type T[ P any] struct{} | ||
type T[P1, P2, P3 any] struct{} | ||
|
||
type T[P C] struct{} | ||
type T[P1,P2, P3 C] struct{} | ||
|
||
type T[P C[P]] struct{} | ||
type T[P1, P2, P3 C[P1,P2,P3]] struct{} | ||
|
||
func f[P any](x P) | ||
func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{} | ||
|
||
func f[P interface{}](x P) | ||
func f[P1, P2, P3 interface{ m1(P1); type P2, P3 }](x1 P1, x2 P2, x3 P3) struct{} | ||
func f[P any](T1[P], T2[P]) T3[P] | ||
|
||
func (x T[P]) m() | ||
func ((T[P])) m(x T[P]) P | ||
|
||
func _() { | ||
type _ []T[P] | ||
var _ []T[P] | ||
_ = []T[P]{} | ||
} |