@@ -142,14 +142,22 @@ object Parsers {
142
142
val length = if offset == in.offset && in.name != null then in.name.show.length else 0
143
143
syntaxError(msg, Span (offset, offset + length))
144
144
lastErrorOffset = in.offset
145
- end if
145
+
146
+ def syntaxError (msg : => String , offset : Int ): Unit =
147
+ syntaxError(msg.toMessage, offset)
148
+
149
+ def syntaxError (msg : => String ): Unit =
150
+ syntaxError(msg, in.offset)
146
151
147
152
/** Unconditionally issue an error at given span, without
148
153
* updating lastErrorOffset.
149
154
*/
150
155
def syntaxError (msg : Message , span : Span ): Unit =
151
156
report.error(msg, source.atSpan(span))
152
157
158
+ def syntaxError (msg : => String , span : Span ): Unit =
159
+ syntaxError(msg.toMessage, span)
160
+
153
161
def unimplementedExpr (using Context ): Select =
154
162
Select (Select (rootDot(nme.scala), nme.Predef ), nme.??? )
155
163
}
@@ -259,9 +267,6 @@ object Parsers {
259
267
in.skip()
260
268
lastErrorOffset = in.offset
261
269
262
- def warning (msg : Message , sourcePos : SourcePosition ): Unit =
263
- report.warning(msg, sourcePos)
264
-
265
270
def warning (msg : Message , offset : Int = in.offset): Unit =
266
271
report.warning(msg, source.atSpan(Span (offset)))
267
272
@@ -283,6 +288,9 @@ object Parsers {
283
288
syntaxError(msg, offset)
284
289
skip()
285
290
291
+ def syntaxErrorOrIncomplete (msg : => String ): Unit =
292
+ syntaxErrorOrIncomplete(msg.toMessage, in.offset)
293
+
286
294
def syntaxErrorOrIncomplete (msg : Message , span : Span ): Unit =
287
295
if in.token == EOF then
288
296
incompleteInputError(msg)
@@ -350,7 +358,7 @@ object Parsers {
350
358
val statFollows = mustStartStatTokens.contains(found)
351
359
syntaxError(
352
360
if noPrevStat then IllegalStartOfStatement (what, isModifier, statFollows)
353
- else i " end of $what expected but ${showToken(found)} found " )
361
+ else i " end of $what expected but ${showToken(found)} found " .toMessage )
354
362
if mustStartStatTokens.contains(found) then
355
363
false // it's a statement that might be legal in an outer context
356
364
else
@@ -610,11 +618,11 @@ object Parsers {
610
618
if in.isNewLine && ! (nextIndentWidth < startIndentWidth) then
611
619
warning(
612
620
if startIndentWidth <= nextIndentWidth then
613
- i """ Line is indented too far to the right, or a `{` is missing before:
621
+ i """ Line is indented too far to the right, or a `{` is missing before:
614
622
|
615
- | ${t.tryToShow}"""
623
+ | ${t.tryToShow}""" .toMessage
616
624
else
617
- in.spaceTabMismatchMsg(startIndentWidth, nextIndentWidth),
625
+ in.spaceTabMismatchMsg(startIndentWidth, nextIndentWidth).toMessage ,
618
626
in.next.offset
619
627
)
620
628
t
@@ -627,7 +635,7 @@ object Parsers {
627
635
if in.isNewLine then
628
636
val nextIndentWidth = in.indentWidth(in.next.offset)
629
637
if in.currentRegion.indentWidth < nextIndentWidth then
630
- warning(i " Line is indented too far to the right, or a `{` or `:` is missing " , in.next.offset)
638
+ warning(i " Line is indented too far to the right, or a `{` or `:` is missing " .toMessage , in.next.offset)
631
639
632
640
/* -------- REWRITES ----------------------------------------------------------- */
633
641
@@ -1732,7 +1740,7 @@ object Parsers {
1732
1740
Ident (tpnme.USCOREkw ).withSpan(Span (start, in.lastOffset, start))
1733
1741
else
1734
1742
if sourceVersion.isAtLeast(future) then
1735
- deprecationWarning(em " `_` is deprecated for wildcard arguments of types: use `?` instead " )
1743
+ deprecationWarning(em " `_` is deprecated for wildcard arguments of types: use `?` instead " .toMessage )
1736
1744
patch(source, Span (in.offset, in.offset + 1 ), " ?" )
1737
1745
val start = in.skipToken()
1738
1746
typeBounds().withSpan(Span (start, in.lastOffset, start))
@@ -2171,10 +2179,11 @@ object Parsers {
2171
2179
else Literal (Constant (())) // finally without an expression
2172
2180
}
2173
2181
else {
2174
- if (handler.isEmpty) warning(
2175
- EmptyCatchAndFinallyBlock (body),
2176
- source.atSpan(Span (tryOffset, endOffset(body)))
2177
- )
2182
+ if handler.isEmpty then
2183
+ report.warning(
2184
+ EmptyCatchAndFinallyBlock (body),
2185
+ source.atSpan(Span (tryOffset, endOffset(body)))
2186
+ )
2178
2187
EmptyTree
2179
2188
}
2180
2189
ParsedTry (body, handler, finalizer)
@@ -2768,7 +2777,7 @@ object Parsers {
2768
2777
warning(i """ Misleading indentation: this expression forms part of the preceding catch case.
2769
2778
|If this is intended, it should be indented for clarity.
2770
2779
|Otherwise, if the handler is intended to be empty, use a multi-line catch with
2771
- |an indented case. """ )
2780
+ |an indented case. """ .toMessage )
2772
2781
expr()
2773
2782
else block()
2774
2783
})
@@ -2989,7 +2998,8 @@ object Parsers {
2989
2998
inBrackets {
2990
2999
if in.token == THIS then
2991
3000
if sourceVersion.isAtLeast(future) then
2992
- deprecationWarning(" The [this] qualifier will be deprecated in the future; it should be dropped." )
3001
+ deprecationWarning(
3002
+ " The [this] qualifier will be deprecated in the future; it should be dropped." .toMessage)
2993
3003
in.nextToken()
2994
3004
mods | Local
2995
3005
else mods.withPrivateWithin(ident().toTypeName)
@@ -3471,7 +3481,8 @@ object Parsers {
3471
3481
if sourceVersion.isAtLeast(future) then
3472
3482
deprecationWarning(
3473
3483
em """ `= _` has been deprecated; use `= uninitialized` instead.
3474
- |`uninitialized` can be imported with `scala.compiletime.uninitialized`. """ , rhsOffset)
3484
+ |`uninitialized` can be imported with `scala.compiletime.uninitialized`. """ .toMessage,
3485
+ rhsOffset)
3475
3486
placeholderParams = placeholderParams.tail
3476
3487
atSpan(rhs0.span) { Ident (nme.WILDCARD ) }
3477
3488
case rhs0 => rhs0
0 commit comments