Skip to content

Commit 7de74bd

Browse files
committed
Use "explain=" to tag an -explain message in an implicitNotFound
This approach mirrors the format used in `@noWarn`. There it is possible to tag encode the category and message in the string. ``` @nowarn("cat=deprecation&msg=Implementation ...") ``` The current implementation for `explain=` only allows this tag at the start of the string. Making the message either a old-style message or an message in the explain. We could extend this to support `msg=` to be able to have both a custom message and an explain. Furthermore we could insert some flags to explicitly state how to display the original message (for example: not-found=hidden, not-found=in-message, not-found=in-explain).
1 parent d6ae0cb commit 7de74bd

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,17 +2640,18 @@ class MissingImplicitArgument(
26402640
recur(pt)
26412641

26422642
/** The implicitNotFound annotation on the parameter, or else on the type.
2643-
* implicitNotFound message strings starting with `...` are intended for
2644-
* additional explanations, not the message proper. The leading `...` is
2643+
* implicitNotFound message strings starting with `explain=` are intended for
2644+
* additional explanations, not the message proper. The leading `explain=` is
26452645
* dropped in this case.
26462646
* @param explain The message is used for an additional explanation, not
26472647
* the message proper.
26482648
*/
26492649
def userDefinedImplicitNotFoundMessage(explain: Boolean)(using Context): Option[String] =
2650+
val explainTag = "explain="
26502651
def filter(msg: Option[String]) = msg match
26512652
case Some(str) =>
2652-
if str.startsWith("...") then
2653-
if explain then Some(str.drop(3)) else None
2653+
if str.startsWith(explainTag) then
2654+
if explain then Some(str.drop(explainTag.length)) else None
26542655
else if explain then None
26552656
else msg
26562657
case None => None

library/src/scala/util/boundary.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object boundary:
3535

3636
/** Labels are targets indicating which boundary will be exited by a `break`.
3737
*/
38-
@implicitNotFound("...A Label is generated from an enclosing `scala.util.boundary` call.\nMaybe that boundary is missing?")
38+
@implicitNotFound("explain=A Label is generated from an enclosing `scala.util.boundary` call.\nMaybe that boundary is missing?")
3939
final class Label[-T]
4040

4141
/** Abort current computation and instead return `value` as the value of
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
object Test:
22
scala.util.boundary.break(1) // error
3-
4-

0 commit comments

Comments
 (0)