Skip to content

Commit a87db21

Browse files
committed
SI-8291 Fix implicitNotFound message with type aliases
This pattern of code is typically a bug: if (f(tp.typeSymbol)) { g(tp.typeArgs) } Intead, one needs to take the base type of `tp` wrt `tp.typeSymbol`. This commit does exactly that when formatting the `@implicitNotFound` custom error message. Patch found on the back of an envelope in the handwriting of @adriaanm
1 parent 7b2c3cb commit a87db21

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,8 +1478,10 @@ trait Implicits {
14781478
})
14791479

14801480
private lazy val typeParamNames: List[String] = sym.typeParams.map(_.decodedName)
1481+
private def typeArgsAtSym(paramTp: Type) = paramTp.baseType(sym).typeArgs
1482+
1483+
def format(paramName: Name, paramTp: Type): String = format(typeArgsAtSym(paramTp) map (_.toString))
14811484

1482-
def format(paramName: Name, paramTp: Type): String = format(paramTp.typeArgs map (_.toString))
14831485
def format(typeArgs: List[String]): String =
14841486
interpolate(msg, Map((typeParamNames zip typeArgs): _*)) // TODO: give access to the name and type of the implicit argument, etc?
14851487

test/files/neg/t8291.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t8291.scala:5: error: Could not find implicit for Int or String
2+
implicitly[X[Int, String]]
3+
^
4+
t8291.scala:6: error: Could not find implicit for Int or String
5+
implicitly[Z[String]]
6+
^
7+
two errors found

test/files/neg/t8291.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@scala.annotation.implicitNotFound("Could not find implicit for ${T} or ${U}") trait X[T, U]
2+
3+
object Test {
4+
type Z[U] = X[Int, U]
5+
implicitly[X[Int, String]]
6+
implicitly[Z[String]]
7+
}

0 commit comments

Comments
 (0)