Skip to content

Commit 9d09247

Browse files
committed
Merge pull request scala#4288 from adriaanm/retronym-ticket/9041
SI-9041 Avoid unreported type error with overloading, implicits
2 parents 2b6a197 + 1970a83 commit 9d09247

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
825825
}
826826
orElse { _ =>
827827
val resetTree = resetAttrs(original)
828+
resetTree match {
829+
case treeInfo.Applied(fun, targs, args) =>
830+
if (fun.symbol != null && fun.symbol.isError)
831+
// SI-9041 Without this, we leak error symbols past the typer!
832+
// because the fallback typechecking notices the error-symbol,
833+
// refuses to re-attempt typechecking, and presumes that someone
834+
// else was responsible for issuing the related type error!
835+
fun.setSymbol(NoSymbol)
836+
case _ =>
837+
}
828838
debuglog(s"fallback on implicits: ${tree}/$resetTree")
829839
val tree1 = typed(resetTree, mode)
830840
// Q: `typed` already calls `pluginsTyped` and `adapt`. the only difference here is that

test/files/neg/t9041.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
t9041.scala:11: error: could not find implicit value for parameter cellSetter: CellSetter[scala.math.BigDecimal]
2+
def setCell(cell: Cell, data: math.BigDecimal) { cell.setCellValue(data) }
3+
^
4+
one error found

test/files/neg/t9041.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// False negative test, requires overloading in Cell.
2+
3+
trait Cell { def setCellValue(i: Int) = () ; def setCellValue(d: Double) = () }
4+
5+
trait Nope {
6+
def f = {
7+
trait CellSetter[A] {
8+
def setCell(cell: Cell, data: A): Unit
9+
}
10+
implicit val bigDecimalCellSetter = new CellSetter[math.BigDecimal]() {
11+
def setCell(cell: Cell, data: math.BigDecimal) { cell.setCellValue(data) }
12+
}
13+
implicit class RichCell(cell: Cell) {
14+
def setCellValue[A](data: A)(implicit cellSetter: CellSetter[A]) = cellSetter.setCell(cell, data)
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)