@@ -142,14 +142,22 @@ object Parsers {
142142 val length = if offset == in.offset && in.name != null then in.name.show.length else 0
143143 syntaxError(msg, Span (offset, offset + length))
144144 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)
146151
147152 /** Unconditionally issue an error at given span, without
148153 * updating lastErrorOffset.
149154 */
150155 def syntaxError (msg : Message , span : Span ): Unit =
151156 report.error(msg, source.atSpan(span))
152157
158+ def syntaxError (msg : => String , span : Span ): Unit =
159+ syntaxError(msg.toMessage, span)
160+
153161 def unimplementedExpr (using Context ): Select =
154162 Select (Select (rootDot(nme.scala), nme.Predef ), nme.??? )
155163 }
@@ -259,9 +267,6 @@ object Parsers {
259267 in.skip()
260268 lastErrorOffset = in.offset
261269
262- def warning (msg : Message , sourcePos : SourcePosition ): Unit =
263- report.warning(msg, sourcePos)
264-
265270 def warning (msg : Message , offset : Int = in.offset): Unit =
266271 report.warning(msg, source.atSpan(Span (offset)))
267272
@@ -283,6 +288,9 @@ object Parsers {
283288 syntaxError(msg, offset)
284289 skip()
285290
291+ def syntaxErrorOrIncomplete (msg : => String ): Unit =
292+ syntaxErrorOrIncomplete(msg.toMessage, in.offset)
293+
286294 def syntaxErrorOrIncomplete (msg : Message , span : Span ): Unit =
287295 if in.token == EOF then
288296 incompleteInputError(msg)
@@ -350,7 +358,7 @@ object Parsers {
350358 val statFollows = mustStartStatTokens.contains(found)
351359 syntaxError(
352360 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 )
354362 if mustStartStatTokens.contains(found) then
355363 false // it's a statement that might be legal in an outer context
356364 else
@@ -610,11 +618,11 @@ object Parsers {
610618 if in.isNewLine && ! (nextIndentWidth < startIndentWidth) then
611619 warning(
612620 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:
614622 |
615- | ${t.tryToShow}"""
623+ | ${t.tryToShow}""" .toMessage
616624 else
617- in.spaceTabMismatchMsg(startIndentWidth, nextIndentWidth),
625+ in.spaceTabMismatchMsg(startIndentWidth, nextIndentWidth).toMessage ,
618626 in.next.offset
619627 )
620628 t
@@ -627,7 +635,7 @@ object Parsers {
627635 if in.isNewLine then
628636 val nextIndentWidth = in.indentWidth(in.next.offset)
629637 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)
631639
632640/* -------- REWRITES ----------------------------------------------------------- */
633641
@@ -1732,7 +1740,7 @@ object Parsers {
17321740 Ident (tpnme.USCOREkw ).withSpan(Span (start, in.lastOffset, start))
17331741 else
17341742 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 )
17361744 patch(source, Span (in.offset, in.offset + 1 ), " ?" )
17371745 val start = in.skipToken()
17381746 typeBounds().withSpan(Span (start, in.lastOffset, start))
@@ -2171,10 +2179,11 @@ object Parsers {
21712179 else Literal (Constant (())) // finally without an expression
21722180 }
21732181 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+ )
21782187 EmptyTree
21792188 }
21802189 ParsedTry (body, handler, finalizer)
@@ -2768,7 +2777,7 @@ object Parsers {
27682777 warning(i """ Misleading indentation: this expression forms part of the preceding catch case.
27692778 |If this is intended, it should be indented for clarity.
27702779 |Otherwise, if the handler is intended to be empty, use a multi-line catch with
2771- |an indented case. """ )
2780+ |an indented case. """ .toMessage )
27722781 expr()
27732782 else block()
27742783 })
@@ -2989,7 +2998,8 @@ object Parsers {
29892998 inBrackets {
29902999 if in.token == THIS then
29913000 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)
29933003 in.nextToken()
29943004 mods | Local
29953005 else mods.withPrivateWithin(ident().toTypeName)
@@ -3471,7 +3481,8 @@ object Parsers {
34713481 if sourceVersion.isAtLeast(future) then
34723482 deprecationWarning(
34733483 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)
34753486 placeholderParams = placeholderParams.tail
34763487 atSpan(rhs0.span) { Ident (nme.WILDCARD ) }
34773488 case rhs0 => rhs0
0 commit comments