aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/typer/ErrorReporting.scala3
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala4
-rw-r--r--src/scala/Eq.scala3
3 files changed, 6 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala
index 69c12e5f5..d3303628e 100644
--- a/src/dotty/tools/dotc/typer/ErrorReporting.scala
+++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala
@@ -11,6 +11,7 @@ import util.Positions._
import reporting.Diagnostic
import printing.Showable
import printing.Disambiguation.disambiguated
+import java.util.regex.Matcher.quoteReplacement
object ErrorReporting {
@@ -124,7 +125,7 @@ object ErrorReporting {
def implicitNotFoundString(raw: String, paramNames: List[String], args: List[Type]): String = {
def translate(name: String): Option[String] = {
val idx = paramNames.indexOf(name)
- if (idx >= 0) Some(args(idx).show) else None
+ if (idx >= 0) Some(quoteReplacement(args(idx).show)) else None
}
"""\$\{\w*\}""".r.replaceSomeIn(raw, m => translate(m.matched.drop(2).init))
}
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index 091bf49f9..f7823b2b3 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -477,9 +477,7 @@ trait Implicits { self: Typer =>
def assumedCanEqual = ltp.isError || rtp.isError || ltp <:< rtp || rtp <:< ltp
if (!ctx.isAfterTyper && !assumedCanEqual) {
val res = inferImplicitArg(
- defn.EqType.appliedTo(ltp, rtp),
- _ => ctx.error(d"Values of types $ltp and $rtp cannot be compared with == or !=", pos),
- pos)
+ defn.EqType.appliedTo(ltp, rtp), msgFun => ctx.error(msgFun(""), pos), pos)
implicits.println(i"Eq witness found: $res: ${res.tpe}")
}
}
diff --git a/src/scala/Eq.scala b/src/scala/Eq.scala
index 697ec4318..6d993ac39 100644
--- a/src/scala/Eq.scala
+++ b/src/scala/Eq.scala
@@ -1,6 +1,9 @@
package scala
+import annotation.implicitNotFound
+
/** A marker class indicating that values of kind `T` can be compared. */
+@implicitNotFound("Values of types ${L} and ${R} cannot be compared with == or !=")
class Eq[-L, -R]
/** Besides being a companion object, this object