-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkers: supported generics for typeDefFirst and paramTypeCombine (#…
- Loading branch information
Showing
6 changed files
with
78 additions
and
4 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
17 changes: 17 additions & 0 deletions
17
checkers/testdata/paramTypeCombine/negative_tests_go118.go
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,17 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package checker_test | ||
|
||
func genericGood1[T any](a T, b, c int) {} | ||
func genericGood2[T any](a, b T, c int) {} | ||
func genericGood3[T any](a T) {} | ||
func genericGood4[T any]() {} | ||
func genericGood5[T any, Y any](a, b T, c int, d, e Y) {} | ||
|
||
func genericUnnamed[T any](T, T) {} | ||
|
||
func genericUnnamedResults[T any]() (T, T) { | ||
var t T | ||
return t, t | ||
} |
21 changes: 21 additions & 0 deletions
21
checkers/testdata/paramTypeCombine/positive_tests_go118.go
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,21 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package checker_test | ||
|
||
/*! func[T any]() (a T, b T, c T) could be replaced with func[T any]() (a, b, c T) */ | ||
func genericSimple1[T any]() (a T, b T, c T) { return a, b, c } | ||
|
||
/*! func[T any](a T, b T, c T) could be replaced with func[T any](a, b, c T) */ | ||
func genericSimple2[T any](a T, b T, c T) {} | ||
|
||
/*! func[T any, Y any](a T, b T, c int, d Y, e Y) could be replaced with func[T any, Y any](a, b T, c int, d, e Y) */ | ||
func genericMixed1[T any, Y any](a T, b T, c int, d Y, e Y) {} | ||
|
||
/*! func[T any, Y any]() (a T, b T, c int, d Y, e Y) could be replaced with func[T any, Y any]() (a, b T, c int, d, e Y) */ | ||
func genericMixed2[T any, Y any]() (a T, b T, c int, d Y, e Y) { return a, b, c, d, e } | ||
|
||
/*! func[T any](a T, b T, c int, d int32, e int32) (f int64, g int64, h T, k T) could be replaced with func[T any](a, b T, c int, d, e int32) (f, g int64, h, k T) */ | ||
func genericMixed3[T any](a T, b T, c int, d int32, e int32) (f int64, g int64, h T, k T) { | ||
return f, g, h, k | ||
} |
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,14 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package checker_test | ||
|
||
type genericNegativeStruct[T any] struct{ _ []T } | ||
|
||
func (_ genericNegativeStruct[T]) Method() {} | ||
func (_ *genericNegativeStruct[T]) MethodWithRef() {} | ||
|
||
type multiGenericNegativeStruct[T any, X any] struct{ _ []T } | ||
|
||
func (_ multiGenericNegativeStruct[T, X]) Method() {} | ||
func (_ *multiGenericNegativeStruct[T, X]) MethodWithRef() {} |
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,14 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package checker_test | ||
|
||
func (_ genericPositiveStruct[T]) Method() {} | ||
|
||
/*! definition of type 'genericPositiveStruct' should appear before its methods */ | ||
type genericPositiveStruct[T any] struct{ _ []T } | ||
|
||
func (_ *multiGenericPositiveStruct[T, X]) MethodWithRef() {} | ||
|
||
/*! definition of type 'multiGenericPositiveStruct' should appear before its methods */ | ||
type multiGenericPositiveStruct[T any, X any] struct{ _ []T } |
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