Skip to content

Commit 856f161

Browse files
committed
Add links to Awsome Error Messages
* Declare `links` as `val` instead. * Added a couple of links to specs and docs
1 parent 9410003 commit 856f161

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/Message.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ object DocumentationLink {
3838
case class TourUrl(text: String, suffix: String) extends DocumentationLink {
3939
val url = s"http://docs.scala-lang.org/overviews/$suffix"
4040
}
41+
case class Sip(text: String, suffix: String) extends DocumentationLink {
42+
val url = s"http://docs.scala-lang.org/sips/$suffix"
43+
}
4144
case class DottyDocs(text: String = "Dotty documentation", suffix: String) extends DocumentationLink {
4245
val url = s"http://dotty.epfl.ch/docs/$suffix"
4346
}
@@ -83,7 +86,10 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
8386
*/
8487
def explanation: String
8588

86-
def links: List[DocumentationLink] = Nil
89+
/** Links may list URLs to Internet resources related to the error
90+
* e.g. the Scala Language Specification.
91+
*/
92+
val links: List[DocumentationLink] = Nil
8793

8894
/** The implicit `Context` in messages is a large thing that we don't want
8995
* persisted. This method gets around that by duplicating the message
@@ -93,8 +99,7 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
9399
val msg = self.msg
94100
val kind = self.kind
95101
val explanation = self.explanation
96-
private val persistedLinks = self.links
97-
override def links = persistedLinks
102+
override val links = self.links
98103
}
99104
}
100105

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ object messages {
107107
TourUrl("More information on implicit classes", "core/implicit-classes.html")
108108
)
109109

110+
private def patternMatchingLinks = List(
111+
LanguageSpec(suffix = "08-pattern-matching.html"),
112+
DottyDocs(suffix = "reference/changed/pattern-matching.html")
113+
)
114+
115+
110116
// Syntax Errors ---------------------------------------------------------- //
111117
abstract class EmptyCatchOrFinallyBlock(tryBody: untpd.Tree, errNo: ErrorMessageID)(implicit ctx: Context)
112118
extends Message(EmptyCatchOrFinallyBlockID) {
@@ -143,7 +149,7 @@ object messages {
143149
|correctly handles transfer functions like ${"return"}."""
144150
}
145151

146-
override def links = tryExpressionLinks
152+
override val links = tryExpressionLinks
147153
}
148154

149155
case class EmptyCatchBlock(tryBody: untpd.Tree)(implicit ctx: Context)
@@ -153,7 +159,7 @@ object messages {
153159
hl"""|The ${"catch"} block does not contain a valid expression, try
154160
|adding a case like - `${"case e: Exception =>"}` to the block"""
155161

156-
override def links = tryExpressionLinks
162+
override val links = tryExpressionLinks
157163
}
158164

159165
case class EmptyCatchAndFinallyBlock(tryBody: untpd.Tree)(implicit ctx: Context)
@@ -163,7 +169,7 @@ object messages {
163169
hl"""|A ${"try"} without ${"catch"} or ${"finally"} is equivalent to putting
164170
|its body in a block; no exceptions are handled."""
165171

166-
override def links = tryExpressionLinks
172+
override val links = tryExpressionLinks
167173
}
168174

169175
case class DeprecatedWithOperator()(implicit ctx: Context)
@@ -176,7 +182,7 @@ object messages {
176182
|use of the ${"with"} keyword. There are a few differences in
177183
|semantics between intersection types and using `${"with"}'."""
178184

179-
override def links = List(
185+
override val links = List(
180186
DottyDocs(suffix = "reference/intersection-types.html")
181187
)
182188
}
@@ -192,7 +198,7 @@ object messages {
192198
|have a singleton representation of ${cdef.name}, use a "${"case object"}".
193199
|Or, add an explicit `()' as a parameter list to ${cdef.name}."""
194200

195-
override def links = List(
201+
override val links = List(
196202
LanguageSpec(suffix = "05-classes-and-objects.html#case-classes")
197203
)
198204
}
@@ -228,7 +234,7 @@ object messages {
228234
|
229235
|${"val f: Seq[Int] => Option[List[Int]] = { case xs @ List(1, 2, 3) => Some(xs) }"} """
230236

231-
override def links = List(
237+
override val links = List(
232238
LanguageSpec(suffix = "06-expressions.html#anonymous-functions")
233239
)
234240
}
@@ -435,7 +441,7 @@ object messages {
435441

436442
}
437443

438-
override def links = List(
444+
override val links = List(
439445
DottyDocs(suffix = "reference/trait-parameters.html")
440446
)
441447
}
@@ -468,7 +474,7 @@ object messages {
468474
|${"import Implicits"}.${cdef.name}"""
469475
}
470476

471-
override def links = implicitClassLinks
477+
override val links = implicitClassLinks
472478
}
473479

474480
case class ImplicitCaseClass(cdef: untpd.TypeDef)(implicit ctx: Context)
@@ -482,7 +488,7 @@ object messages {
482488
|${"implicit class"} ${cdef.name}...
483489
|"""
484490

485-
override def links = implicitClassLinks
491+
override val links = implicitClassLinks
486492
}
487493

488494
case class ImplicitClassPrimaryConstructorArity()(implicit ctx: Context)
@@ -572,7 +578,7 @@ object messages {
572578
|"""
573579
}
574580

575-
override def links = List(
581+
override val links = List(
576582
TourUrl("More on String Interpolation", "core/string-interpolation.html")
577583
)
578584
}
@@ -828,6 +834,7 @@ object messages {
828834
|
829835
|$fixedVarInAlternative"""
830836
}
837+
override val links = patternMatchingLinks
831838
}
832839

833840
case class IdentifierExpected(identifier: String)(implicit ctx: Context)
@@ -907,6 +914,10 @@ object messages {
907914
| - String Literals: "Hello, World!"
908915
| - null
909916
|"""
917+
918+
override val links = List(
919+
LanguageSpec(suffix = "01-lexical-syntax.html#literals")
920+
)
910921
}
911922

912923
case class PatternMatchExhaustivity(uncovered: String)(implicit ctx: Context)
@@ -924,6 +935,8 @@ object messages {
924935
| - If an extractor always return 'Some(...)', write 'Some[X]' for its return type
925936
| - Add a 'case _ => ...' at the end to match all remaining cases
926937
|"""
938+
939+
override val links = patternMatchingLinks
927940
}
928941

929942
case class UncheckedTypePattern(msg: String)(implicit ctx: Context)
@@ -943,6 +956,7 @@ object messages {
943956
val kind = s"""Match ${hl"case"} Unreachable"""
944957
val msg = "unreachable code"
945958
val explanation = ""
959+
override val links = patternMatchingLinks
946960
}
947961

948962
case class SeqWildcardPatternPos()(implicit ctx: Context)
@@ -967,6 +981,7 @@ object messages {
967981
|
968982
|would give 3 as a result"""
969983
}
984+
override val links = patternMatchingLinks
970985
}
971986

972987
case class IllegalStartOfSimplePattern()(implicit ctx: Context)
@@ -1077,6 +1092,9 @@ object messages {
10771092
|
10781093
|${"List[_]"}
10791094
|"""
1095+
override val links = List(
1096+
DottyDocs(suffix = "reference/dropped/existential-types.html")
1097+
)
10801098
}
10811099

10821100
case class UnboundWildcardType()(implicit ctx: Context)
@@ -1263,6 +1281,9 @@ object messages {
12631281
| (all other special characters)
12641282
|Operators starting with a letter have lowest precedence, followed by operators starting with `|`, etc.
12651283
|""".stripMargin
1284+
override val links = List(
1285+
LanguageSpec(suffix = "06-expressions.html#infix-operations")
1286+
)
12661287
}
12671288

12681289
case class CantInstantiateAbstractClassOrTrait(cls: Symbol, isTrait: Boolean)(implicit ctx: Context)
@@ -1737,7 +1758,7 @@ object messages {
17371758
|In this instance, the modifier combination is not supported"""
17381759
}
17391760

1740-
override def links: List[DocumentationLink] = List(
1761+
override val links = List(
17411762
LanguageSpec("Please see the official Scala Language Specification section on modifiers",
17421763
"05-classes-and-objects.html#modifiers"))
17431764
}
@@ -1758,6 +1779,9 @@ object messages {
17581779
|
17591780
|$code2""".stripMargin
17601781
}
1782+
override val links = List(
1783+
DottyDocs(suffix = "reference/implicit-function-types.html")
1784+
)
17611785
}
17621786

17631787
case class WrongNumberOfParameters(expected: Int)(implicit ctx: Context)
@@ -1781,6 +1805,9 @@ object messages {
17811805
val msg = "expected start of definition"
17821806
val explanation =
17831807
hl"you have to provide either ${"class"}, ${"trait"}, ${"object"}, or ${"enum"} definitions after qualifiers"
1808+
override val links = List(
1809+
LanguageSpec(suffix = "09-top-level-definitions.html")
1810+
)
17841811
}
17851812

17861813
case class NoReturnFromInline(owner: Symbol)(implicit ctx: Context)

0 commit comments

Comments
 (0)