@@ -391,37 +391,45 @@ object Inferencing {
391
391
* - The prefix `p` of a selection `p.f`.
392
392
* - The result expression `e` of a block `{s1; .. sn; e}`.
393
393
*/
394
- def tvarsInParams (tree : Tree , locked : TypeVars )(using Context ): List [TypeVar ] = {
395
- @ tailrec def boundVars (tree : Tree , acc : List [TypeVar ]): List [TypeVar ] = tree match {
396
- case Apply (fn, _) => boundVars(fn, acc)
397
- case TypeApply (fn, targs) =>
398
- val tvars = targs.filter(_.isInstanceOf [InferredTypeTree ]).tpes.collect {
399
- case tvar : TypeVar
400
- if ! tvar.isInstantiated &&
401
- ctx.typerState.ownedVars.contains(tvar) &&
402
- ! locked.contains(tvar) => tvar
403
- }
404
- boundVars(fn, acc ::: tvars)
405
- case Select (pre, _) => boundVars(pre, acc)
406
- case Block (_, expr) => boundVars(expr, acc)
407
- case _ => acc
394
+ def tvarsInParams (tree : Tree , locked : TypeVars )(using Context ): List [TypeVar ] = trace.log(i " tvarsInParams $tree" ) {
395
+ // @tailrec
396
+ def boundVars (tree : Tree , acc : List [TypeVar ]): List [TypeVar ] = trace.log(i " boundVars $tree" ) {
397
+ tree match {
398
+ case Apply (fn, args) =>
399
+ val argTpVars = args.flatMap(boundVars(_, Nil ))
400
+ boundVars(fn, acc ++ argTpVars)
401
+ case TypeApply (fn, targs) =>
402
+ val tvars = targs.filter(_.isInstanceOf [InferredTypeTree ]).tpes.collect {
403
+ case tvar : TypeVar
404
+ if ! tvar.isInstantiated &&
405
+ ctx.typerState.ownedVars.contains(tvar) &&
406
+ ! locked.contains(tvar) => tvar
407
+ }
408
+ boundVars(fn, acc ::: tvars)
409
+ case Select (pre, _) => boundVars(pre, acc)
410
+ case Block (_, expr) => boundVars(expr, acc)
411
+ case _ => acc
412
+ }
408
413
}
409
- @ tailrec def occurring (tree : Tree , toTest : List [TypeVar ], acc : List [TypeVar ]): List [TypeVar ] =
414
+ // @tailrec
415
+ def occurring (tree : Tree , toTest : List [TypeVar ], acc : List [TypeVar ]): List [TypeVar ] = trace.log(i " occurring $tree" ) {
410
416
if (toTest.isEmpty) acc
411
417
else tree match {
412
- case Apply (fn, _) =>
418
+ case Apply (fn, args) =>
419
+ val argOcc = args.flatMap(occurring(_, toTest, Nil ))
413
420
fn.tpe.widen match {
414
421
case mtp : MethodType =>
415
422
val (occ, nocc) = toTest.partition(tvar => mtp.paramInfos.exists(tvar.occursIn))
416
- occurring(fn, nocc, occ ::: acc)
423
+ occurring(fn, nocc, occ ::: acc ::: argOcc )
417
424
case _ =>
418
- occurring(fn, toTest, acc)
425
+ occurring(fn, toTest, acc ::: argOcc )
419
426
}
420
427
case TypeApply (fn, targs) => occurring(fn, toTest, acc)
421
428
case Select (pre, _) => occurring(pre, toTest, acc)
422
429
case Block (_, expr) => occurring(expr, toTest, acc)
423
430
case _ => acc
424
431
}
432
+ }
425
433
occurring(tree, boundVars(tree, Nil ), Nil )
426
434
}
427
435
0 commit comments