Skip to content

Commit 127a767

Browse files
retronymadriaanm
authored andcommitted
SI-8129 Crack the case of the curiously incoherent Context
- Typer is created with Context. - Typer creates an Inferencer with said Context. - Typer mutates Typer#context after each import statement - Typer mutates its current Context (e.g to disable implicits.) - Typer asks a question of Inferencer - Inferencer, looking at the old context, thinks that implicits are allowed - Inferencer saves implicit ambiguities into the wrong Context. Because of this bug, overload resolution in blocks or template bodies for applications that follow an import have been considering implicit coercions in the first try at static overload resolution, and, in the rare case that it encounters an ambigous implicit in the process, leaking an unpositioned ambiguout error. This commit ensures coherency between `typer.context` and `typer.infer.context` by making the latter delegate to the former.
1 parent 4a8edc0 commit 127a767

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ trait Infer extends Checkable {
174174
private lazy val stdErrorValue = stdErrorClass.newErrorValue(nme.ERROR)
175175

176176
/** The context-dependent inferencer part */
177-
class Inferencer(context: Context) extends InferencerContextErrors with InferCheckable {
177+
abstract class Inferencer extends InferencerContextErrors with InferCheckable {
178+
def context: Context
178179
import InferErrorGen._
179180

180181
/* -- Error Messages --------------------------------------------------- */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
109109

110110
private val transformed: mutable.Map[Tree, Tree] = unit.transformed
111111

112-
val infer = new Inferencer(context0) {
112+
val infer = new Inferencer {
113+
def context = Typer.this.context
113114
// See SI-3281 re undoLog
114115
override def isCoercible(tp: Type, pt: Type) = undoLog undo viewExists(tp, pt)
115116
}
File renamed without changes.

0 commit comments

Comments
 (0)