@@ -512,10 +512,6 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
512
512
513
513
named .SetTypeParams (r .typeParamNames ())
514
514
515
- // TODO(mdempsky): Rewrite receiver types to underlying is an
516
- // Interface? The go/types importer does this (I think because
517
- // unit tests expected that), but cmd/compile doesn't care
518
- // about it, so maybe we can avoid worrying about that here.
519
515
rhs := r .typ ()
520
516
pk := r .p
521
517
pk .laterFor (named , func () {
@@ -527,6 +523,28 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) {
527
523
f () // initialize RHS
528
524
}
529
525
underlying := rhs .Underlying ()
526
+
527
+ // If the underlying type is an interface, we need to
528
+ // duplicate its methods so we can replace the receiver
529
+ // parameter's type (#49906).
530
+ if iface , ok := underlying .(* types.Interface ); ok && iface .NumExplicitMethods () != 0 {
531
+ methods := make ([]* types.Func , iface .NumExplicitMethods ())
532
+ for i := range methods {
533
+ fn := iface .ExplicitMethod (i )
534
+ sig := fn .Type ().(* types.Signature )
535
+
536
+ recv := types .NewVar (fn .Pos (), fn .Pkg (), "" , named )
537
+ methods [i ] = types .NewFunc (fn .Pos (), fn .Pkg (), fn .Name (), types .NewSignature (recv , sig .Params (), sig .Results (), sig .Variadic ()))
538
+ }
539
+
540
+ embeds := make ([]types.Type , iface .NumEmbeddeds ())
541
+ for i := range embeds {
542
+ embeds [i ] = iface .EmbeddedType (i )
543
+ }
544
+
545
+ underlying = types .NewInterfaceType (methods , embeds )
546
+ }
547
+
530
548
named .SetUnderlying (underlying )
531
549
})
532
550
0 commit comments