@@ -206,15 +206,17 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
206206 def SyntheticValDef (name : TermName , rhs : Tree )(using Context ): ValDef =
207207 ValDef (newSymbol(ctx.owner, name, Synthetic , rhs.tpe.widen, coord = rhs.span), rhs)
208208
209- def DefDef (sym : TermSymbol , tparams : List [TypeSymbol ], vparamss : List [List [ TermSymbol ]],
209+ def DefDef (sym : TermSymbol , paramss : List [List [Symbol ]],
210210 resultType : Type , rhs : Tree )(using Context ): DefDef =
211- sym.setParamss(tparams :: vparamss )
211+ sym.setParamss(paramss )
212212 ta.assignType(
213213 untpd.DefDef (
214214 sym.name,
215- joinParams(
216- tparams.map(tparam => TypeDef (tparam).withSpan(tparam.span)),
217- vparamss.nestedMap(vparam => ValDef (vparam).withSpan(vparam.span))),
215+ paramss.map {
216+ case TypeSymbols (params) => params.map(param => TypeDef (param).withSpan(param.span))
217+ case TermSymbols (params) => params.map(param => ValDef (param).withSpan(param.span))
218+ case _ => ???
219+ },
218220 TypeTree (resultType),
219221 rhs),
220222 sym)
@@ -223,7 +225,57 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
223225 ta.assignType(DefDef (sym, Function .const(rhs) _), sym)
224226
225227 def DefDef (sym : TermSymbol , rhsFn : List [List [Tree ]] => Tree )(using Context ): DefDef =
226- polyDefDef(sym, Function .const(rhsFn))
228+
229+ // Map method type `tp` with remaining parameters stored in rawParamss to
230+ // final result type and all (given or synthesized) parameters
231+ def recur (tp : Type , remaining : List [List [Symbol ]]): (Type , List [List [Symbol ]]) = tp match
232+ case tp : PolyType =>
233+ val (tparams : List [TypeSymbol ], remaining1) = remaining match
234+ case tparams :: remaining1 =>
235+ assert(tparams.hasSameLengthAs(tp.paramNames) && tparams.head.isType)
236+ (tparams.asInstanceOf [List [TypeSymbol ]], remaining1)
237+ case nil =>
238+ (newTypeParams(sym, tp.paramNames, EmptyFlags , tp.instantiateParamInfos(_)), Nil )
239+ val (rtp, paramss) = recur(tp.instantiate(tparams.map(_.typeRef)), remaining1)
240+ (rtp, tparams :: paramss)
241+ case tp : MethodType =>
242+ val isParamDependent = tp.isParamDependent
243+ val previousParamRefs = if isParamDependent then mutable.ListBuffer [TermRef ]() else null
244+
245+ def valueParam (name : TermName , origInfo : Type ): TermSymbol =
246+ val maybeImplicit =
247+ if tp.isContextualMethod then Given
248+ else if tp.isImplicitMethod then Implicit
249+ else EmptyFlags
250+ val maybeErased = if tp.isErasedMethod then Erased else EmptyFlags
251+
252+ def makeSym (info : Type ) = newSymbol(sym, name, TermParam | maybeImplicit | maybeErased, info, coord = sym.coord)
253+
254+ if isParamDependent then
255+ val sym = makeSym(origInfo.substParams(tp, previousParamRefs.toList))
256+ previousParamRefs += sym.termRef
257+ sym
258+ else makeSym(origInfo)
259+ end valueParam
260+
261+ val (vparams : List [TermSymbol ], remaining1) =
262+ if tp.paramNames.isEmpty then (Nil , remaining)
263+ else remaining match
264+ case vparams :: remaining1 =>
265+ assert(vparams.hasSameLengthAs(tp.paramNames) && vparams.head.isTerm)
266+ (vparams.asInstanceOf [List [TermSymbol ]], remaining1)
267+ case nil =>
268+ (tp.paramNames.lazyZip(tp.paramInfos).map(valueParam), Nil )
269+ val (rtp, paramss) = recur(tp.instantiate(vparams.map(_.termRef)), remaining1)
270+ (rtp, vparams :: paramss)
271+ case _ =>
272+ assert(remaining.isEmpty)
273+ (tp.widenExpr, Nil )
274+ end recur
275+
276+ val (rtp, paramss) = recur(sym.info, sym.rawParamss)
277+ DefDef (sym, paramss, rtp, rhsFn(paramss.nestedMap(ref)))
278+ end DefDef
227279
228280 /** A DefDef with given method symbol `sym`.
229281 * @rhsFn A function from type parameter types and term parameter references
@@ -285,7 +337,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
285337 val targs = tparams.map(tparam => ref(tparam.typeRef))
286338 val argss = vparamss.nestedMap(vparam => Ident (vparam.termRef))
287339 sym.setParamss(tparams :: vparamss)
288- DefDef (sym, tparams, vparamss, rtp, rhsFn(targs)(argss))
340+ DefDef (sym, joinSymbols( tparams, vparamss) , rtp, rhsFn(targs)(argss))
289341 }
290342
291343 def TypeDef (sym : TypeSymbol )(using Context ): TypeDef =
0 commit comments