@@ -40,6 +40,9 @@ object CheckCaptures:
4040 val name : String = " cc"
4141 val description : String = " capture checking"
4242
43+ /** An attachment to prevent widening of arguments to tracked parameters */
44+ val NoWiden : Property .Key [Unit ] = Property .Key ()
45+
4346 enum EnvKind derives CanEqual :
4447 case Regular // normal case
4548 case NestedInOwner // environment is a temporary one nested in the owner's environment,
@@ -829,6 +832,7 @@ class CheckCaptures extends Recheck, SymTransformer:
829832 // - the selection is either a trackable capture reference or a pure type, or
830833 // - if the selection is of a parameterless method capturing a ResultCap
831834 if noWiden(selType, pt)
835+ || tree.hasAttachment(NoWiden )
832836 || qualType.isBoxedCapturing
833837 || selType.isBoxedCapturing
834838 || selWiden.isBoxedCapturing
@@ -885,6 +889,11 @@ class CheckCaptures extends Recheck, SymTransformer:
885889 * TODO: Maybe not charge deep capture sets for consume?
886890 */
887891 protected override def recheckArg (arg : Tree , formal : Type , pref : ParamRef , app : Apply )(using Context ): Type =
892+ val meth = app.fun.symbol
893+ if meth.isPrimaryConstructor
894+ && meth.owner.asClass.refiningGetterNamed(pref.paramName).is(Tracked )
895+ then
896+ arg.putAttachment(NoWiden , ())
888897 val instantiatedFormal = globalCapToLocal(formal, Origin .Formal (pref, app))
889898 val argType = recheck(arg, instantiatedFormal)
890899 .showing(i " recheck arg $arg vs $instantiatedFormal = $result" , capt)
@@ -1980,7 +1989,7 @@ class CheckCaptures extends Recheck, SymTransformer:
19801989 * - do box adaptation
19811990 */
19821991 def adapt (actual : Type , expected : Type , tree : Tree )(using Context ): Type =
1983- if noWiden(actual, expected) then
1992+ if noWiden(actual, expected) || tree.removeAttachment( NoWiden ).isDefined then
19841993 expected match
19851994 case expected @ CapturingType (_, _) if expected.isBoxed =>
19861995 // actual is a singleton type and expected is of the form box x.type^cs.
0 commit comments