-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add error message - Comments.scala:128 #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,5 +543,42 @@ object messages { | |
| | ||
|""".stripMargin | ||
} | ||
|
||
|
||
case class ProperDefinitionNotFound()(implicit ctx: Context) extends Message(20) { | ||
val kind = "Definition Not Found" | ||
val msg = hl"""|Proper definition was not found in ${"@usecase"}""" | ||
|
||
val noUsecase = "def map[B, That](f: A => B)(implicit bf: CanBuildFrom[List[A], B, That]): That" | ||
|
||
val usecase = | ||
"""|/** Map from List[A] => List[B] | ||
| * | ||
| * @usecase def map[B](f: A => B): List[B] | ||
| */ | ||
|def map[B, That](f: A => B)(implicit bf: CanBuildFrom[List[A], B, That]): That""".stripMargin | ||
|
||
val explanation = { | ||
hl"""|${"@usecase"} are only supported for ${"def"}s. They exist because with Scala's | ||
|advanced type-system, we sometimes end up with seemingly scary signatures. | ||
| | ||
|Let's see an example using the `map`function: | ||
| | ||
|${"List(1, 2, 3).map(2 * _) // res: List(2, 4, 6)"} | ||
| | ||
|It's very straight forward to understand and use, but has such a scary signature: | ||
| | ||
|$noUsecase | ||
| | ||
|In order to mitigate this and ease the usage of such functions we have the ${"@usecase"} | ||
|annotation for docstrings. Which can be used like this: | ||
| | ||
|$usecase | ||
| | ||
|Now when creating the docs, the method signature is substituted by the | ||
|${"@usecase"} with a reader-friendly version. The compiler makes sure that it is valid. | ||
| | ||
|Because of this, you must use ${"def"} when defining ${"@usecase"}.""".stripMargin | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel that this explanation still needs some improvement - I feel that it is not clear where you should put the As I mentioned before - val explanation = {
val noUsecase =
"def map[B, That](f: A => B)(implicit bf: CanBuildFrom[List[A], B, That]): That"
val usecase =
"""|/** Map from List[A] => List[B]
| *
| * @usecase def map[B](f: A => B): List[B]
| */
|def map[B, That](f: A => B)(implicit bf: CanBuildFrom[List[A], B, That]): That""".stripMargin
hl"""|Usecases are only supported for ${"def"}s. They exist because with Scala's
|advanced type-system, we sometimes end up with seemingly scary signatures.
|The usage of these methods, however, needs not be - for instance the `map`
|function
|
|${"List(1, 2, 3).map(2 * _) // res: List(2, 4, 6)"}
|
|is easy to understand and use - but has a rather bulky signature:
|
|$noUsecase
|
|to mitigate this and ease the usage of such functions we have the ${"@usecase"}
|annotation for docstrings. Which can be used like this:
|
|$usecase
|
|When creating the docs, the signature of the method is substituted by the
|usecase and the compiler makes sure that it is valid. Because of this, you're
|only allowed to use ${"def"}s when defining usecases.""".stripMargin
} could be the basis for your explanation :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well done again :) Thank you! |
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get a good sense of what's going on here for the error message's explanation there are a couple of things you (or the user) need(s) to know:
@usecase
?untpd.DefDef
here?