Skip to content

Commit

Permalink
SI-8129 Crack the case of the curiously incoherent Context
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
retronym authored and adriaanm committed Feb 10, 2014
1 parent 4a8edc0 commit 127a767
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Infer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ trait Infer extends Checkable {
private lazy val stdErrorValue = stdErrorClass.newErrorValue(nme.ERROR)

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

/* -- Error Messages --------------------------------------------------- */
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper

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

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

0 comments on commit 127a767

Please sign in to comment.