Skip to content

Commit 2d07ae8

Browse files
authored
Merge pull request #6400 from dotty-staging/fix-contextbounds
Fix #4996: Properly drop context bounds in type lambdas
2 parents 9d7d05d + 4d51cd7 commit 2d07ae8

29 files changed

+19
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ object desugar {
211211
case _ =>
212212
rhs
213213
}
214+
215+
def dropContextBounds(tparam: TypeDef): TypeDef = {
216+
def dropInRhs(rhs: Tree): Tree = rhs match {
217+
case ContextBounds(tbounds, _) =>
218+
tbounds
219+
case rhs @ LambdaTypeTree(tparams, body) =>
220+
cpy.LambdaTypeTree(rhs)(tparams, dropInRhs(body))
221+
case _ =>
222+
rhs
223+
}
224+
cpy.TypeDef(tparam)(rhs = dropInRhs(tparam.rhs))
225+
}
226+
214227
val tparams1 = tparams mapConserve { tparam =>
215228
cpy.TypeDef(tparam)(rhs = desugarContextBounds(tparam.rhs))
216229
}
@@ -239,17 +252,12 @@ object desugar {
239252
def normalizedVparamss = meth1.vparamss map (_ map (vparam =>
240253
cpy.ValDef(vparam)(rhs = EmptyTree)))
241254

242-
def dropContextBound(tparam: TypeDef) = tparam.rhs match {
243-
case ContextBounds(tbounds, _) => cpy.TypeDef(tparam)(rhs = tbounds)
244-
case _ => tparam
245-
}
246-
247255
def defaultGetters(vparamss: List[List[ValDef]], n: Int): List[DefDef] = vparamss match {
248256
case (vparam :: vparams) :: vparamss1 =>
249257
def defaultGetter: DefDef =
250258
DefDef(
251259
name = DefaultGetterName(methName, n),
252-
tparams = meth.tparams.map(tparam => dropContextBound(toDefParam(tparam))),
260+
tparams = meth.tparams.map(tparam => dropContextBounds(toDefParam(tparam))),
253261
vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam), n),
254262
tpt = TypeTree(),
255263
rhs = vparam.rhs

tests/pos/i4996.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Foo {
2+
trait M[A[_]]
3+
def foo[i0[_] : M](a: List[String] = ???) = ???
4+
}

tests/run/module-serialization-proxy-class-unload.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ object Test {
1414
// This would "java.lang.OutOfMemoryError: Java heap space" if ModuleSerializationProxy
1515
// prevented class unloading.
1616
deserializeDynamicLoadedClass()
17+
System.gc()
1718
}
1819
}
1920

0 commit comments

Comments
 (0)