@@ -392,8 +392,10 @@ object Inferencing {
392
392
* - The result expression `e` of a block `{s1; .. sn; e}`.
393
393
*/
394
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)
395
+ def boundVars (tree : Tree , acc : List [TypeVar ]): List [TypeVar ] = tree match {
396
+ case Apply (fn, args) =>
397
+ val argTpVars = args.flatMap(boundVars(_, Nil ))
398
+ boundVars(fn, acc ++ argTpVars)
397
399
case TypeApply (fn, targs) =>
398
400
val tvars = targs.filter(_.isInstanceOf [InferredTypeTree ]).tpes.collect {
399
401
case tvar : TypeVar
@@ -406,16 +408,18 @@ object Inferencing {
406
408
case Block (_, expr) => boundVars(expr, acc)
407
409
case _ => acc
408
410
}
409
- @ tailrec def occurring (tree : Tree , toTest : List [TypeVar ], acc : List [TypeVar ]): List [TypeVar ] =
411
+ def occurring (tree : Tree , toTest : List [TypeVar ], acc : List [TypeVar ]): List [TypeVar ] =
410
412
if (toTest.isEmpty) acc
411
413
else tree match {
412
- case Apply (fn, _) =>
414
+ case Apply (fn, args) =>
415
+ val argsOcc = args.flatMap(occurring(_, toTest, Nil ))
416
+ val argsNocc = toTest.filterNot(argsOcc.contains)
413
417
fn.tpe.widen match {
414
418
case mtp : MethodType =>
415
- val (occ, nocc) = toTest .partition(tvar => mtp.paramInfos.exists(tvar.occursIn))
416
- occurring(fn, nocc, occ ::: acc)
419
+ val (occ, nocc) = argsNocc .partition(tvar => mtp.paramInfos.exists(tvar.occursIn))
420
+ occurring(fn, nocc, occ ::: argsOcc ::: acc)
417
421
case _ =>
418
- occurring(fn, toTest, acc)
422
+ occurring(fn, argsNocc, argsOcc ::: acc)
419
423
}
420
424
case TypeApply (fn, targs) => occurring(fn, toTest, acc)
421
425
case Select (pre, _) => occurring(pre, toTest, acc)
0 commit comments