Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go/types/typeutil/unify.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ func Unify(x, y types.Type, unifier map[*types.TypeParam]types.Type) bool {
}

if !uni(x, y) {
clear(unifier)
return false
}

Expand Down
20 changes: 20 additions & 0 deletions go/types/typeutil/unify_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package typeutil

import (
"go/types"
"testing"
)

func TestUnifyFailurePreservesExistingBindings(t *testing.T) {
pkg := types.NewPackage("p", "p")
constraint := types.NewInterfaceType(nil, nil).Complete()
param := types.NewTypeParam(types.NewTypeName(0, pkg, "T", nil), constraint)
bindings := map[*types.TypeParam]types.Type{param: types.Typ[types.Int]}

if Unify(param, types.Typ[types.Bool], bindings) {
t.Fatal("Unify succeeded with a conflicting existing binding")
}
if got := bindings[param]; got != types.Typ[types.Int] {
t.Fatalf("binding after failed Unify = %v, want int", got)
}
}