@@ -11,6 +11,7 @@ import config.{Config, Feature}
1111import ast.{tpd, untpd, Trees}
1212import Trees.*
1313import typer.RefChecks.{checkAllOverrides, checkSelfAgainstParents}
14+ import typer.Checking.{checkBounds, checkAppliedTypesIn}
1415import util.{SimpleIdentitySet, EqHashMap, SrcPos}
1516import transform.SymUtils.*
1617import transform.{Recheck, PreRecheck}
@@ -911,8 +912,27 @@ class CheckCaptures extends Recheck, SymTransformer:
911912 |The type needs to be declared explicitly.""", t.srcPos)
912913 case _ =>
913914 inferred.foreachPart(checkPure, StopAt.Static)
915+ case t @ TypeApply(fun, args) =>
916+ fun.knownType.widen match
917+ case tl: PolyType =>
918+ val normArgs = args.lazyZip(tl.paramInfos).map { (arg, bounds) =>
919+ arg.withType(arg.knownType.forceBoxStatus(
920+ bounds.hi.isBoxedCapturing | bounds.lo.isBoxedCapturing))
921+ }
922+ checkBounds(normArgs, tl)
923+ case _ =>
914924 case _ =>
915925 }
916-
926+ if !ctx.reporter.errorsReported then
927+ // We dont report errors hre if previous errors were reported, because other
928+ // errors often result in bad applied types, but flagging these bad types gives
929+ // often worse error messages than the original errors.
930+ val checkApplied = new TreeTraverser:
931+ def traverse(t: Tree)(using Context) = t match
932+ case tree: InferredTypeTree =>
933+ case tree: New =>
934+ case tree: TypeTree => checkAppliedTypesIn(tree.withKnownType)
935+ case _ => traverseChildren(t)
936+ checkApplied.traverse(unit)
917937 end CaptureChecker
918938end CheckCaptures
0 commit comments