@@ -53,11 +53,6 @@ const (
53
53
// the core types, if any, of non-local (unbound) type parameters.
54
54
enableCoreTypeUnification = true
55
55
56
- // If enableInterfaceInference is set, type inference uses
57
- // shared methods for improved type inference involving
58
- // interfaces.
59
- enableInterfaceInference = true
60
-
61
56
// If traceInference is set, unification will print a trace of its operation.
62
57
// Interpretation of trace:
63
58
// x ≡ y attempt to unify types x and y
@@ -81,15 +76,16 @@ type unifier struct {
81
76
// that inferring the type for a given type parameter P will
82
77
// automatically infer the same type for all other parameters
83
78
// unified (joined) with P.
84
- handles map [* TypeParam ]* Type
85
- depth int // recursion depth during unification
79
+ handles map [* TypeParam ]* Type
80
+ depth int // recursion depth during unification
81
+ enableInterfaceInference bool // use shared methods for better inference
86
82
}
87
83
88
84
// newUnifier returns a new unifier initialized with the given type parameter
89
85
// and corresponding type argument lists. The type argument list may be shorter
90
86
// than the type parameter list, and it may contain nil types. Matching type
91
87
// parameters and arguments must have the same index.
92
- func newUnifier (tparams []* TypeParam , targs []Type ) * unifier {
88
+ func newUnifier (tparams []* TypeParam , targs []Type , enableInterfaceInference bool ) * unifier {
93
89
assert (len (tparams ) >= len (targs ))
94
90
handles := make (map [* TypeParam ]* Type , len (tparams ))
95
91
// Allocate all handles up-front: in a correct program, all type parameters
@@ -103,7 +99,7 @@ func newUnifier(tparams []*TypeParam, targs []Type) *unifier {
103
99
}
104
100
handles [x ] = & t
105
101
}
106
- return & unifier {handles , 0 }
102
+ return & unifier {handles , 0 , enableInterfaceInference }
107
103
}
108
104
109
105
// unifyMode controls the behavior of the unifier.
@@ -339,7 +335,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
339
335
// we will fail at function instantiation or argument assignment time.
340
336
//
341
337
// If we have at least one defined type, there is one in y.
342
- if ny , _ := y .(* Named ); mode & exact == 0 && ny != nil && isTypeLit (x ) && ! (enableInterfaceInference && IsInterface (x )) {
338
+ if ny , _ := y .(* Named ); mode & exact == 0 && ny != nil && isTypeLit (x ) && ! (u . enableInterfaceInference && IsInterface (x )) {
343
339
if traceInference {
344
340
u .tracef ("%s ≡ under %s" , x , ny )
345
341
}
@@ -437,12 +433,12 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
437
433
emode |= exact
438
434
}
439
435
440
- // If EnableInterfaceInference is set and we don't require exact unification,
436
+ // If u. EnableInterfaceInference is set and we don't require exact unification,
441
437
// if both types are interfaces, one interface must have a subset of the
442
438
// methods of the other and corresponding method signatures must unify.
443
439
// If only one type is an interface, all its methods must be present in the
444
440
// other type and corresponding method signatures must unify.
445
- if enableInterfaceInference && mode & exact == 0 {
441
+ if u . enableInterfaceInference && mode & exact == 0 {
446
442
// One or both interfaces may be defined types.
447
443
// Look under the name, but not under type parameters (go.dev/issue/60564).
448
444
xi := asInterface (x )
@@ -632,7 +628,7 @@ func (u *unifier) nify(x, y Type, mode unifyMode, p *ifacePair) (result bool) {
632
628
}
633
629
634
630
case * Interface :
635
- assert (! enableInterfaceInference || mode & exact != 0 ) // handled before this switch
631
+ assert (! u . enableInterfaceInference || mode & exact != 0 ) // handled before this switch
636
632
637
633
// Two interface types unify if they have the same set of methods with
638
634
// the same names, and corresponding function types unify.
0 commit comments