@@ -419,8 +419,9 @@ object Types extends TypeUtils {
419419 typeSymbol eq defn.RepeatedParamClass
420420
421421 /** Is this a parameter type that allows implicit argument converson? */
422- def isConvertibleParam (using Context ): Boolean =
423- typeSymbol eq defn.IntoType
422+ def isInto (using Context ): Boolean = this match
423+ case AnnotatedType (_, annot) => annot.symbol == defn.IntoParamAnnot
424+ case _ => false
424425
425426 /** Is this the type of a method that has a repeated parameter type as
426427 * last parameter type?
@@ -1927,7 +1928,9 @@ object Types extends TypeUtils {
19271928 case res => res
19281929 }
19291930 defn.FunctionNOf (
1930- mt.paramInfos.mapConserve(_.translateFromRepeated(toArray = isJava)),
1931+ mt.paramInfos.mapConserve:
1932+ _.translateFromRepeated(toArray = isJava)
1933+ .mapIntoAnnot(defn.IntoParamAnnot , null ),
19311934 result1, isContextual)
19321935 if mt.hasErasedParams then
19331936 defn.PolyFunctionOf (mt)
@@ -1975,6 +1978,38 @@ object Types extends TypeUtils {
19751978 case _ => this
19761979 }
19771980
1981+ /** A mapping between mapping one kind of into annotation to another or
1982+ * dropping into annotations.
1983+ * @param from the into annotation to map
1984+ * @param to either the replacement annotation symbol, or `null`
1985+ * in which case the `from` annotations are dropped.
1986+ */
1987+ def mapIntoAnnot (from : ClassSymbol , to : ClassSymbol | Null )(using Context ): Type = this match
1988+ case self @ AnnotatedType (tp, annot) =>
1989+ val tp1 = tp.mapIntoAnnot(from, to)
1990+ if annot.symbol == from then
1991+ if to == null then tp1
1992+ else AnnotatedType (tp1, Annotation (to, annot.tree.span))
1993+ else self.derivedAnnotatedType(tp1, annot)
1994+ case AppliedType (tycon, arg :: Nil ) if tycon.typeSymbol == defn.RepeatedParamClass =>
1995+ val arg1 = arg.mapIntoAnnot(from, to)
1996+ if arg1 eq arg then this
1997+ else AppliedType (tycon, arg1 :: Nil )
1998+ case defn.FunctionOf (argTypes, resType, isContextual) =>
1999+ val resType1 = resType.mapIntoAnnot(from, to)
2000+ if resType1 eq resType then this
2001+ else defn.FunctionOf (argTypes, resType1, isContextual)
2002+ case RefinedType (parent, rname, mt : MethodOrPoly ) =>
2003+ val mt1 = mt.mapIntoAnnot(from, to)
2004+ if mt1 eq mt then this
2005+ else RefinedType (parent.mapIntoAnnot(from, to), rname, mt1)
2006+ case mt : MethodOrPoly =>
2007+ mt.derivedLambdaType(resType = mt.resType.mapIntoAnnot(from, to))
2008+ case tp : ExprType =>
2009+ tp.derivedExprType(tp.resType.mapIntoAnnot(from, to))
2010+ case _ =>
2011+ this
2012+
19782013 /** A type capturing `ref` */
19792014 def capturing (ref : CaptureRef )(using Context ): Type =
19802015 if captureSet.accountsFor(ref) then this
@@ -4122,6 +4157,7 @@ object Types extends TypeUtils {
41224157 /** Produce method type from parameter symbols, with special mappings for repeated
41234158 * and inline parameters:
41244159 * - replace @repeated annotations on Seq or Array types by <repeated> types
4160+ * - map into annotations to $into annotations
41254161 * - add @inlineParam to inline parameters
41264162 * - add @erasedParam to erased parameters
41274163 * - wrap types of parameters that have an @allowConversions annotation with Into[_]
@@ -4131,34 +4167,14 @@ object Types extends TypeUtils {
41314167 case ExprType (resType) => ExprType (addAnnotation(resType, cls, param))
41324168 case _ => AnnotatedType (tp, Annotation (cls, param.span))
41334169
4134- def wrapConvertible (tp : Type ) =
4135- AppliedType (defn.IntoType .typeRef, tp :: Nil )
4136-
4137- /** Add `Into[..] to the type itself and if it is a function type, to all its
4138- * curried result type(s) as well.
4139- */
4140- def addInto (tp : Type ): Type = tp match
4141- case tp @ AppliedType (tycon, args) if tycon.typeSymbol == defn.RepeatedParamClass =>
4142- tp.derivedAppliedType(tycon, addInto(args.head) :: Nil )
4143- case tp @ AppliedType (tycon, args) if defn.isFunctionNType(tp) =>
4144- wrapConvertible(tp.derivedAppliedType(tycon, args.init :+ addInto(args.last)))
4145- case tp @ defn.RefinedFunctionOf (rinfo) =>
4146- wrapConvertible(tp.derivedRefinedType(refinedInfo = addInto(rinfo)))
4147- case tp : MethodOrPoly =>
4148- tp.derivedLambdaType(resType = addInto(tp.resType))
4149- case ExprType (resType) =>
4150- ExprType (addInto(resType))
4151- case _ =>
4152- wrapConvertible(tp)
4153-
41544170 def paramInfo (param : Symbol ) =
4155- var paramType = param.info.annotatedToRepeated
4171+ var paramType = param.info
4172+ .annotatedToRepeated
4173+ .mapIntoAnnot(defn.IntoAnnot , defn.IntoParamAnnot )
41564174 if param.is(Inline ) then
41574175 paramType = addAnnotation(paramType, defn.InlineParamAnnot , param)
41584176 if param.is(Erased ) then
41594177 paramType = addAnnotation(paramType, defn.ErasedParamAnnot , param)
4160- if param.hasAnnotation(defn.AllowConversionsAnnot ) then
4161- paramType = addInto(paramType)
41624178 paramType
41634179
41644180 apply(params.map(_.name.asTermName))(
0 commit comments