Skip to content

Commit f62d35b

Browse files
committed
Merge pull request scala#2138 from retronym/ticket/6576-null-strikes-back
SI-6576 Workaround / diagnostic for IDE NPE.
2 parents 9398131 + 19649d4 commit f62d35b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ trait Namers extends MethodSynthesis {
908908
// to use. clazz is the ModuleClass. sourceModule works also for classes defined in methods.
909909
val module = clazz.sourceModule
910910
for (cda <- module.attachments.get[ConstructorDefaultsAttachment]) {
911+
debuglog(s"Storing the template namer in the ConstructorDefaultsAttachment of ${module.debugLocationString}.")
911912
cda.companionModuleClassNamer = templateNamer
912913
}
913914
val classTp = ClassInfoType(parents, decls, clazz)
@@ -1229,8 +1230,11 @@ trait Namers extends MethodSynthesis {
12291230
// module's templateNamer to classAndNamerOfModule
12301231
module.attachments.get[ConstructorDefaultsAttachment] match {
12311232
// by martin: the null case can happen in IDE; this is really an ugly hack on top of an ugly hack but it seems to work
1232-
// later by lukas: disabled when fixing SI-5975, i think it cannot happen anymore
1233-
case Some(cda) /*if cma.companionModuleClassNamer == null*/ =>
1233+
case Some(cda) =>
1234+
if (cda.companionModuleClassNamer == null) {
1235+
debugwarn(s"SI-6576 The companion module namer for $meth was unexpectedly null")
1236+
return
1237+
}
12341238
val p = (cda.classWithDefault, cda.companionModuleClassNamer)
12351239
moduleNamer = Some(p)
12361240
p

0 commit comments

Comments
 (0)