Skip to content

Commit 77dbd3b

Browse files
committed
Add a Context parameter to Message
This will be the basis on which we modify contexts for printing diagnsotics.
1 parent ff705aa commit 77dbd3b

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object Decorators {
5959
end extension
6060

6161
extension (str: => String)
62-
def toMessage: Message = NoExplanation(str)
62+
def toMessage: Message = NoExplanation(str)(using NoContext)
6363

6464
/** Implements a findSymbol method on iterators of Symbols that
6565
* works like find but avoids Option, replacing None with NoSymbol.

compiler/src/dotty/tools/dotc/core/TypeErrors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import config.Printers.cyclicErrors
1616

1717
abstract class TypeError(using creationContext: Context) extends Exception(""):
1818

19-
/** Convert to message. This uses an additional Context, so that we
19+
/** Convert to message. This takes an additional Context, so that we
2020
* use the context when the message is first produced, i.e. when the TypeError
2121
* is handled. This makes a difference for CyclicErrors since we need to know
2222
* the context where the completed symbol is referenced, but the creation
@@ -26,7 +26,7 @@ abstract class TypeError(using creationContext: Context) extends Exception(""):
2626
*/
2727
def toMessage(using Context): Message
2828

29-
/** Uses creation context to produce the message */
29+
/** Uses creationContext to produce the message */
3030
override def getMessage: String = toMessage.message
3131

3232
object TypeError:

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package xml
66
import scala.language.unsafeNulls
77

88
import scala.collection.mutable
9+
import core.Contexts.Context
910
import mutable.{ Buffer, ArrayBuffer, ListBuffer }
1011
import scala.util.control.ControlThrowable
1112
import util.Chars.SU
@@ -50,7 +51,7 @@ object MarkupParsers {
5051
override def getMessage: String = "input ended while parsing XML"
5152
}
5253

53-
class MarkupParser(parser: Parser, final val preserveWS: Boolean)(implicit src: SourceFile) extends MarkupParserCommon {
54+
class MarkupParser(parser: Parser, final val preserveWS: Boolean)(using Context) extends MarkupParserCommon {
5455

5556
import Tokens.{ LBRACE, RBRACE }
5657

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object Message {
4040
* @param errorId a unique id identifying the message, this will be
4141
* used to reference documentation online
4242
*/
43-
abstract class Message(val errorId: ErrorMessageID) { self =>
43+
abstract class Message(val errorId: ErrorMessageID)(using Context) { self =>
4444
import Message._
4545

4646
/** The `msg` contains the diagnostic message e.g:
@@ -144,7 +144,7 @@ abstract class Message(val errorId: ErrorMessageID) { self =>
144144
}
145145

146146
/** The fallback `Message` containing no explanation and having no `kind` */
147-
class NoExplanation(msgFn: => String) extends Message(ErrorMessageID.NoExplanationID) {
147+
class NoExplanation(msgFn: => String)(using Context) extends Message(ErrorMessageID.NoExplanationID) {
148148
def msg: String = msgFn
149149
def explain: String = ""
150150
val kind: MessageKind = MessageKind.NoKind

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ import cc.CaptureSet.IdentityCaptRefMap
4040
* ```
4141
*/
4242

43-
abstract class SyntaxMsg(errorId: ErrorMessageID) extends Message(errorId):
43+
abstract class SyntaxMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
4444
def kind = MessageKind.Syntax
4545

46-
abstract class TypeMsg(errorId: ErrorMessageID) extends Message(errorId):
46+
abstract class TypeMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
4747
def kind = MessageKind.Type
4848

4949
trait ShowMatchTrace(tps: Type*)(using Context) extends Message:
@@ -55,27 +55,27 @@ import cc.CaptureSet.IdentityCaptRefMap
5555
def explain = err.whyNoMatchStr(found, expected)
5656
override def canExplain = true
5757

58-
abstract class NamingMsg(errorId: ErrorMessageID) extends Message(errorId):
58+
abstract class NamingMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
5959
def kind = MessageKind.Naming
6060

61-
abstract class DeclarationMsg(errorId: ErrorMessageID) extends Message(errorId):
61+
abstract class DeclarationMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
6262
def kind = MessageKind.Declaration
6363

6464
/** A simple not found message (either for idents, or member selection.
6565
* Messages of this class are sometimes dropped in favor of other, more
6666
* specific messages.
6767
*/
68-
abstract class NotFoundMsg(errorId: ErrorMessageID) extends Message(errorId):
68+
abstract class NotFoundMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
6969
def kind = MessageKind.NotFound
7070
def name: Name
7171

72-
abstract class PatternMatchMsg(errorId: ErrorMessageID) extends Message(errorId):
72+
abstract class PatternMatchMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
7373
def kind = MessageKind.PatternMatch
7474

75-
abstract class CyclicMsg(errorId: ErrorMessageID) extends Message(errorId):
75+
abstract class CyclicMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
7676
def kind = MessageKind.Cyclic
7777

78-
abstract class ReferenceMsg(errorId: ErrorMessageID) extends Message(errorId):
78+
abstract class ReferenceMsg(errorId: ErrorMessageID)(using Context) extends Message(errorId):
7979
def kind = MessageKind.Reference
8080

8181
abstract class EmptyCatchOrFinallyBlock(tryBody: untpd.Tree, errNo: ErrorMessageID)(using Context)
@@ -1097,7 +1097,7 @@ import cc.CaptureSet.IdentityCaptRefMap
10971097
|"""
10981098
}
10991099

1100-
class OverrideError(override val msg: String) extends DeclarationMsg(OverrideErrorID):
1100+
class OverrideError(override val msg: String)(using Context) extends DeclarationMsg(OverrideErrorID):
11011101
def explain = ""
11021102

11031103
class OverrideTypeMismatchError(override val msg: String, memberTp: Type, otherTp: Type)(using Context)

0 commit comments

Comments
 (0)