Skip to content

Commit 5ed8fd0

Browse files
committed
Fix crasher regression with implicit classes and default params
Since the changes to make the compiler output deterministic, default getter symbols must be entered eagerly before the trees are created. This happens in `enterDefDef`, but that method is bypassed when entering the synthetic symbol for an implicit class factory method. This commit enters the default getter symbols in this case, as well, avoiding a later crash.
1 parent bce8bee commit 5ed8fd0

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ trait MethodSynthesis {
231231
val methDef = factoryMeth(classDef.mods & AccessFlags | METHOD | IMPLICIT | SYNTHETIC, classDef.name.toTermName, classDef)
232232
val methSym = enterInScope(assignMemberSymbol(methDef))
233233
context.unit.synthetics(methSym) = methDef
234+
235+
treeInfo.firstConstructor(classDef.impl.body) match {
236+
case primaryConstructor: DefDef =>
237+
if (mexists(primaryConstructor.vparamss)(_.mods.hasDefault))
238+
enterDefaultGetters(methSym, primaryConstructor, primaryConstructor.vparamss, primaryConstructor.tparams)
239+
case _ =>
240+
}
234241
methSym setInfo implicitFactoryMethodCompleter(methDef, classDef.symbol)
235242
}
236243

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
default
2+
default
3+
default
4+
explicit
5+
explicit
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object Test {
2+
implicit class C(self: String)(implicit val foo: String = "default") {
3+
def test = foo
4+
}
5+
6+
implicit class WorkaroundOk(self: String)(implicit val foo: String) {
7+
def this(self: String, dummy: AnyRef = null) { this(self)("")}
8+
}
9+
10+
def main(args: Array[String]) {
11+
println("".foo)
12+
println(C("").foo)
13+
println(new C("").foo)
14+
println(C("")("explicit").foo)
15+
println(new C("")("explicit").foo)
16+
}
17+
}

0 commit comments

Comments
 (0)