@@ -430,10 +430,14 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def *
430
430
// evaluate arguments
431
431
targs := check .typeList (xlist )
432
432
if targs == nil {
433
- def .setUnderlying (Typ [Invalid ]) // avoid later errors due to lazy instantiation
433
+ def .setUnderlying (Typ [Invalid ]) // avoid errors later due to lazy instantiation
434
434
return Typ [Invalid ]
435
435
}
436
436
437
+ // enableTypeTypeInference controls whether to infer missing type arguments
438
+ // using constraint type inference. See issue #51527.
439
+ const enableTypeTypeInference = false
440
+
437
441
// create the instance
438
442
ctxt := check .bestContext (nil )
439
443
h := ctxt .instanceHash (orig , targs )
@@ -453,14 +457,15 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def *
453
457
def .setUnderlying (inst )
454
458
455
459
inst .resolver = func (ctxt * Context , n * Named ) (* TypeParamList , Type , * methodList ) {
456
- tparams := orig .TypeParams ().list ()
460
+ tparams := n . orig .TypeParams ().list ()
457
461
458
- if len (targs ) < len (tparams ) {
462
+ targs := n .targs .list ()
463
+ if enableTypeTypeInference && len (targs ) < len (tparams ) {
459
464
// If inference fails, len(inferred) will be 0, and inst.underlying will
460
465
// be set to Typ[Invalid] in expandNamed.
461
466
inferred := check .infer (x .Pos (), tparams , targs , nil , nil )
462
467
if len (inferred ) > len (targs ) {
463
- inst .targs = newTypeList (inferred )
468
+ n .targs = newTypeList (inferred )
464
469
}
465
470
}
466
471
@@ -473,10 +478,10 @@ func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def *
473
478
// and so it must be resolved during type-checking so that we can report
474
479
// errors.
475
480
inst .resolve (ctxt )
476
- check .recordInstance (x , inst .TypeArgs ().list (), inst )
477
481
// Since check is non-nil, we can still mutate inst. Unpinning the resolver
478
482
// frees some memory.
479
483
inst .resolver = nil
484
+ check .recordInstance (x , inst .TypeArgs ().list (), inst )
480
485
481
486
if check .validateTArgLen (x .Pos (), inst .tparams .Len (), inst .targs .Len ()) {
482
487
if i , err := check .verify (x .Pos (), inst .tparams .list (), inst .targs .list ()); err != nil {
0 commit comments