Skip to content

Commit a2c3956

Browse files
committed
Fix desugaring of classes with context bounds
Context bounds did not make it before into secondary constructors. Now the evidence parameters generated by context bounds get copied into secondary constructors. Without this fix, scala.collection.immutable.PagedSeq fails to compile in new classtag scheme.
1 parent 1ffb63e commit a2c3956

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,7 @@ object desugar {
147147
tparam
148148
}
149149

150-
val meth1 = epbuf.toList match {
151-
case Nil =>
152-
meth
153-
case evidenceParams =>
154-
val vparamss1 = vparamss.reverse match {
155-
case (vparams @ (vparam :: _)) :: rvparamss if vparam.mods is Implicit =>
156-
((vparams ++ evidenceParams) :: rvparamss).reverse
157-
case _ =>
158-
vparamss :+ evidenceParams
159-
}
160-
cpy.DefDef(meth)(tparams = tparams1, vparamss = vparamss1)
161-
}
150+
val meth1 = addEvidenceParams(cpy.DefDef(meth)(tparams = tparams1), epbuf.toList)
162151

163152
/** The longest prefix of parameter lists in vparamss whose total length does not exceed `n` */
164153
def takeUpTo(vparamss: List[List[ValDef]], n: Int): List[List[ValDef]] = vparamss match {
@@ -204,6 +193,30 @@ object desugar {
204193
}
205194
}
206195

196+
// Add all evidence parameters in `params` as implicit parameters to `meth` */
197+
private def addEvidenceParams(meth: DefDef, params: List[ValDef])(implicit ctx: Context): DefDef =
198+
params match {
199+
case Nil =>
200+
meth
201+
case evidenceParams =>
202+
val vparamss1 = meth.vparamss.reverse match {
203+
case (vparams @ (vparam :: _)) :: rvparamss if vparam.mods is Implicit =>
204+
((vparams ++ evidenceParams) :: rvparamss).reverse
205+
case _ =>
206+
meth.vparamss :+ evidenceParams
207+
}
208+
cpy.DefDef(meth)(vparamss = vparamss1)
209+
}
210+
211+
/** The implicit evidence parameters of `meth`, as generated by `desugar.defDef` */
212+
private def evidenceParams(meth: DefDef)(implicit ctx: Context): List[ValDef] =
213+
meth.vparamss.reverse match {
214+
case (vparams @ (vparam :: _)) :: _ if vparam.mods is Implicit =>
215+
vparams.dropWhile(!_.name.startsWith(nme.EVIDENCE_PARAM_PREFIX))
216+
case _ =>
217+
Nil
218+
}
219+
207220
/** Fill in empty type bounds with Nothing/Any. Expand private local type parameters as follows:
208221
*
209222
* class C[v T]
@@ -255,10 +268,13 @@ object desugar {
255268
else constr1.vparamss.nestedMap(toDefParam)
256269
val constr = cpy.DefDef(constr1)(tparams = constrTparams, vparamss = constrVparamss)
257270

258-
// Add constructor type parameters to auxiliary constructors
271+
// Add constructor type parameters and evidence implicit parameters
272+
// to auxiliary constructors
259273
val normalizedBody = impl.body map {
260274
case ddef: DefDef if ddef.name.isConstructorName =>
261-
cpy.DefDef(ddef)(tparams = constrTparams)
275+
addEvidenceParams(
276+
cpy.DefDef(ddef)(tparams = constrTparams),
277+
evidenceParams(constr1).map(toDefParam))
262278
case stat =>
263279
stat
264280
}

0 commit comments

Comments
 (0)