diff options
Diffstat (limited to 'src/go/types/subst.go')
-rw-r--r-- | src/go/types/subst.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/go/types/subst.go b/src/go/types/subst.go index c05e51d425..322e30d357 100644 --- a/src/go/types/subst.go +++ b/src/go/types/subst.go @@ -148,12 +148,12 @@ func (subst *subster) typ(typ Type) Type { } case *Union: - types, copied := subst.typeList(t.types) + terms, copied := subst.termList(t.terms) if copied { // TODO(gri) Remove duplicates that may have crept in after substitution // (unlikely but possible). This matters for the Identical // predicate on unions. - return newUnion(types, t.tilde) + return &Union{terms} } case *Interface: @@ -393,3 +393,21 @@ func (subst *subster) typeList(in []Type) (out []Type, copied bool) { } return } + +func (subst *subster) termList(in []*term) (out []*term, copied bool) { + out = in + for i, t := range in { + if u := subst.typ(t.typ); u != t.typ { + if !copied { + // first function that got substituted => allocate new out slice + // and copy all functions + new := make([]*term, len(in)) + copy(new, out) + out = new + copied = true + } + out[i] = &term{t.tilde, u} + } + } + return +} |