@@ -685,12 +685,6 @@ func TestCollector_NestedRecursiveTypeParams(t *testing.T) {
685
685
}
686
686
687
687
func TestCollector_NestedTypeParams (t * testing.T ) {
688
- // TODO(grantnelson-wf): This test is failing because the type parameters
689
- // inside of U are not being resolved to concrete types. This is because
690
- // when instantiating X in the collector, we are not resolving the
691
- // nested type of U that is X's type argument. This leave the A in U
692
- // as a type parameter instead of resolving it to string.
693
-
694
688
// This is based off of part of go1.19.13/test/typeparam/nested.go
695
689
src := `package test
696
690
func F[A any]() any {
@@ -704,24 +698,33 @@ func TestCollector_NestedTypeParams(t *testing.T) {
704
698
`
705
699
706
700
f := srctesting .New (t )
701
+ tc := types .NewContext ()
707
702
file := f .Parse (`test.go` , src )
708
703
info , pkg := f .Check (`test` , file )
709
704
710
705
c := Collector {
711
- TContext : types . NewContext () ,
706
+ TContext : tc ,
712
707
Info : info ,
713
708
Instances : & PackageInstanceSets {},
714
709
}
715
710
c .Scan (pkg , file )
716
711
717
712
uAny := srctesting .LookupObj (pkg , `F.U` )
718
- uInt , err := types .Instantiate (types .NewContext (), uAny .Type (), []types.Type {types .Typ [types .Int ]}, true )
713
+ resolver := NewResolver (tc , Instance {
714
+ Object : uAny ,
715
+ TNest : []types.Type {types .Typ [types .Int ]},
716
+ TArgs : []types.Type {types .Typ [types .Bool ]},
717
+ })
718
+ // Substitute will only substitute type parameters in generic types but
719
+ // will not instantiate any generic type by applying the type arguments,
720
+ // therefore we need to instantiate first.
721
+ uBool , err := types .Instantiate (tc , uAny .Type (), []types.Type {types .Typ [types .Bool ]}, true )
719
722
if err != nil {
720
- t .Fatalf ("Failed to instantiate U[int ]: %v" , err )
723
+ t .Fatalf ("Failed to instantiate U[bool ]: %v" , err )
721
724
}
722
- //TODO(grantnelson-wf): Need to instantiate uInt to replace `A` with `int` in the struct.
723
- if isGeneric (uInt ) {
724
- t .Errorf ("Expected uInt to be non-generic , got %v" , uInt .Underlying ())
725
+ uIntBool := resolver . Substitute ( uBool )
726
+ if isGeneric (uIntBool ) {
727
+ t .Errorf ("Expected uInt to be concrete , got %v:%v " , uIntBool , uIntBool .Underlying ())
725
728
}
726
729
727
730
want := []Instance {
@@ -735,13 +738,15 @@ func TestCollector_NestedTypeParams(t *testing.T) {
735
738
}, {
736
739
Object : srctesting .LookupObj (pkg , `F.T` ),
737
740
TNest : []types.Type {types .Typ [types .Int ]},
738
- TArgs : []types.Type {uInt }, // TODO(grantnelson-wf): This still had a type param in it that needs to be resolved.
741
+ TArgs : []types.Type {uIntBool },
739
742
},
740
743
}
741
744
got := c .Instances .Pkg (pkg ).Values ()
742
745
if diff := cmp .Diff (want , got , instanceOpts ()); diff != `` {
743
746
t .Errorf ("Instances from Collector contain diff (-want,+got):\n %s" , diff )
744
747
}
748
+
749
+ t .Fail ()
745
750
}
746
751
747
752
func evalTypeArgs (t * testing.T , fSet * token.FileSet , pkg * types.Package , expr string ) []types.Type {
0 commit comments