@@ -419,8 +419,9 @@ object Types extends TypeUtils {
419
419
typeSymbol eq defn.RepeatedParamClass
420
420
421
421
/** 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
424
425
425
426
/** Is this the type of a method that has a repeated parameter type as
426
427
* last parameter type?
@@ -1927,7 +1928,9 @@ object Types extends TypeUtils {
1927
1928
case res => res
1928
1929
}
1929
1930
defn.FunctionNOf (
1930
- mt.paramInfos.mapConserve(_.translateFromRepeated(toArray = isJava)),
1931
+ mt.paramInfos.mapConserve:
1932
+ _.translateFromRepeated(toArray = isJava)
1933
+ .mapIntoAnnot(defn.IntoParamAnnot , null ),
1931
1934
result1, isContextual)
1932
1935
if mt.hasErasedParams then
1933
1936
defn.PolyFunctionOf (mt)
@@ -1975,6 +1978,38 @@ object Types extends TypeUtils {
1975
1978
case _ => this
1976
1979
}
1977
1980
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
+
1978
2013
/** A type capturing `ref` */
1979
2014
def capturing (ref : CaptureRef )(using Context ): Type =
1980
2015
if captureSet.accountsFor(ref) then this
@@ -4122,6 +4157,7 @@ object Types extends TypeUtils {
4122
4157
/** Produce method type from parameter symbols, with special mappings for repeated
4123
4158
* and inline parameters:
4124
4159
* - replace @repeated annotations on Seq or Array types by <repeated> types
4160
+ * - map into annotations to $into annotations
4125
4161
* - add @inlineParam to inline parameters
4126
4162
* - add @erasedParam to erased parameters
4127
4163
* - wrap types of parameters that have an @allowConversions annotation with Into[_]
@@ -4131,34 +4167,14 @@ object Types extends TypeUtils {
4131
4167
case ExprType (resType) => ExprType (addAnnotation(resType, cls, param))
4132
4168
case _ => AnnotatedType (tp, Annotation (cls, param.span))
4133
4169
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
-
4154
4170
def paramInfo (param : Symbol ) =
4155
- var paramType = param.info.annotatedToRepeated
4171
+ var paramType = param.info
4172
+ .annotatedToRepeated
4173
+ .mapIntoAnnot(defn.IntoAnnot , defn.IntoParamAnnot )
4156
4174
if param.is(Inline ) then
4157
4175
paramType = addAnnotation(paramType, defn.InlineParamAnnot , param)
4158
4176
if param.is(Erased ) then
4159
4177
paramType = addAnnotation(paramType, defn.ErasedParamAnnot , param)
4160
- if param.hasAnnotation(defn.AllowConversionsAnnot ) then
4161
- paramType = addInto(paramType)
4162
4178
paramType
4163
4179
4164
4180
apply(params.map(_.name.asTermName))(
0 commit comments