@@ -25,6 +25,7 @@ import (
25
25
"runtime"
26
26
"sort"
27
27
"strings"
28
+ "sync"
28
29
"testing"
29
30
"time"
30
31
@@ -769,6 +770,72 @@ func TestIssue51836(t *testing.T) {
769
770
_ = importPkg (t , "./testdata/aa" , tmpdir )
770
771
}
771
772
773
+ func TestIssue61561 (t * testing.T ) {
774
+ testenv .NeedsGo1Point (t , 18 ) // requires generics
775
+
776
+ const src = `package p
777
+
778
+ type I[P any] interface {
779
+ m(P)
780
+ n() P
781
+ }
782
+
783
+ type J = I[int]
784
+
785
+ type StillBad[P any] *interface{b(P)}
786
+
787
+ type K = StillBad[string]
788
+ `
789
+ fset := token .NewFileSet ()
790
+ f , err := goparser .ParseFile (fset , "p.go" , src , 0 )
791
+ if f == nil {
792
+ // Some test cases may have parse errors, but we must always have a
793
+ // file.
794
+ t .Fatalf ("ParseFile returned nil file. Err: %v" , err )
795
+ }
796
+
797
+ config := & types.Config {}
798
+ pkg1 , err := config .Check ("p" , fset , []* ast.File {f }, nil )
799
+ if err != nil {
800
+ t .Fatal (err )
801
+ }
802
+
803
+ // Export it. (Shallowness isn't important here.)
804
+ data , err := IExportShallow (fset , pkg1 , nil )
805
+ if err != nil {
806
+ t .Fatalf ("export: %v" , err ) // any failure to export is a bug
807
+ }
808
+
809
+ // Re-import it.
810
+ imports := make (map [string ]* types.Package )
811
+ pkg2 , err := IImportShallow (fset , GetPackagesFromMap (imports ), data , "p" , nil )
812
+ if err != nil {
813
+ t .Fatalf ("import: %v" , err ) // any failure of IExport+IImport is a bug.
814
+ }
815
+
816
+ insts := []types.Type {
817
+ pkg2 .Scope ().Lookup ("J" ).Type (),
818
+ // This test is still racy, because the incomplete interface is contained
819
+ // within a nested type expression.
820
+ //
821
+ // Uncomment this once golang/go#61561 is fixed.
822
+ // pkg2.Scope().Lookup("K").Type().Underlying().(*types.Pointer).Elem(),
823
+ }
824
+
825
+ // Use the interface instances concurrently.
826
+ for _ , inst := range insts {
827
+ var wg sync.WaitGroup
828
+ for i := 0 ; i < 2 ; i ++ {
829
+ wg .Add (1 )
830
+ go func () {
831
+ defer wg .Done ()
832
+ _ = types .NewMethodSet (inst )
833
+ }()
834
+ }
835
+ wg .Wait ()
836
+ }
837
+ }
838
+
772
839
func TestIssue57015 (t * testing.T ) {
773
840
testenv .NeedsGo1Point (t , 18 ) // requires generics
774
841
0 commit comments