Skip to content

Drop toNoExplanation implicit conversion #16211

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

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.util.control.NonFatal
import Contexts._, Names._, Phases._, Symbols._
import printing.{ Printer, Showable }, printing.Formatting._, printing.Texts._
import transform.MegaPhase
import reporting.{Message, NoExplanation}

/** This object provides useful implicit decorators for types defined elsewhere */
object Decorators {
Expand Down Expand Up @@ -57,6 +58,9 @@ object Decorators {
padding + s.replace("\n", "\n" + padding)
end extension

extension (str: => String)
def toMessage: Message = reporting.NoExplanation(str)

/** Implements a findSymbol method on iterators of Symbols that
* works like find but avoids Option, replacing None with NoSymbol.
*/
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class TypeError(msg: String) extends Exception(msg) {
def this() = this("")
final def toMessage(using Context): Message =
withMode(Mode.Printing)(produceMessage)
def produceMessage(using Context): Message = super.getMessage.nn
def produceMessage(using Context): Message = super.getMessage.nn.toMessage
override def getMessage: String = super.getMessage.nn
}

class MalformedType(pre: Type, denot: Denotation, absMembers: Set[Name]) extends TypeError {
override def produceMessage(using Context): Message =
i"malformed type: $pre is not a legal prefix for $denot because it contains abstract type member${if (absMembers.size == 1) "" else "s"} ${absMembers.mkString(", ")}"
.toMessage
}

class MissingType(pre: Type, name: Name) extends TypeError {
Expand All @@ -38,6 +39,7 @@ class MissingType(pre: Type, name: Name) extends TypeError {
if (ctx.debug) printStackTrace()
i"""cannot resolve reference to type $pre.$name
|the classfile defining the type might be missing from the classpath${otherReason(pre)}"""
.toMessage
}
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5296,16 +5296,18 @@ object Types {
val et = new PreviousErrorType
ctx.base.errorTypeMsg(et) = m
et
def apply(s: => String)(using Context): ErrorType =
apply(s.toMessage)
end ErrorType

class PreviousErrorType extends ErrorType:
def msg(using Context): Message =
ctx.base.errorTypeMsg.get(this) match
case Some(m) => m
case None => "error message from previous run no longer available"
case None => "error message from previous run no longer available".toMessage

object UnspecifiedErrorType extends ErrorType {
override def msg(using Context): Message = "unspecified error"
override def msg(using Context): Message = "unspecified error".toMessage
}

/* Type used to track Select nodes that could not resolve a member and their qualifier is a scala.Dynamic. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import printing.Texts._
import printing.Printer
import io.AbstractFile
import util.common._
import util.NoSourcePosition
import typer.Checking.checkNonCyclic
import typer.Nullables._
import transform.SymUtils._
Expand Down Expand Up @@ -744,7 +745,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val anyTypes = boundSyms map (_ => defn.AnyType)
val boundBounds = boundSyms map (_.info.bounds.hi)
val tp2 = tp1.subst(boundSyms, boundBounds).subst(boundSyms, anyTypes)
report.warning(FailureToEliminateExistential(tp, tp1, tp2, boundSyms, classRoot.symbol))
report.warning(FailureToEliminateExistential(tp, tp1, tp2, boundSyms, classRoot.symbol), NoSourcePosition)
tp2
}
else tp1
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ object Inlines:
tree,
i"""|Maximal number of $reason (${setting.value}) exceeded,
|Maybe this is caused by a recursive inline method?
|You can use ${setting.name} to change the limit.""",
|You can use ${setting.name} to change the limit.""".toMessage,
(tree :: enclosingInlineds).last.srcPos
)
if ctx.base.stopInlining && enclosingInlineds.isEmpty then
Expand Down
45 changes: 28 additions & 17 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ object Parsers {
val length = if offset == in.offset && in.name != null then in.name.show.length else 0
syntaxError(msg, Span(offset, offset + length))
lastErrorOffset = in.offset
end if

def syntaxError(msg: => String, offset: Int): Unit =
syntaxError(msg.toMessage, offset)

def syntaxError(msg: => String): Unit =
syntaxError(msg, in.offset)

/** Unconditionally issue an error at given span, without
* updating lastErrorOffset.
*/
def syntaxError(msg: Message, span: Span): Unit =
report.error(msg, source.atSpan(span))

def syntaxError(msg: => String, span: Span): Unit =
syntaxError(msg.toMessage, span)

def unimplementedExpr(using Context): Select =
Select(Select(rootDot(nme.scala), nme.Predef), nme.???)
}
Expand Down Expand Up @@ -259,9 +267,6 @@ object Parsers {
in.skip()
lastErrorOffset = in.offset

def warning(msg: Message, sourcePos: SourcePosition): Unit =
report.warning(msg, sourcePos)

def warning(msg: Message, offset: Int = in.offset): Unit =
report.warning(msg, source.atSpan(Span(offset)))

Expand All @@ -283,6 +288,9 @@ object Parsers {
syntaxError(msg, offset)
skip()

def syntaxErrorOrIncomplete(msg: => String): Unit =
syntaxErrorOrIncomplete(msg.toMessage, in.offset)

def syntaxErrorOrIncomplete(msg: Message, span: Span): Unit =
if in.token == EOF then
incompleteInputError(msg)
Expand Down Expand Up @@ -350,7 +358,7 @@ object Parsers {
val statFollows = mustStartStatTokens.contains(found)
syntaxError(
if noPrevStat then IllegalStartOfStatement(what, isModifier, statFollows)
else i"end of $what expected but ${showToken(found)} found")
else i"end of $what expected but ${showToken(found)} found".toMessage)
if mustStartStatTokens.contains(found) then
false // it's a statement that might be legal in an outer context
else
Expand Down Expand Up @@ -610,11 +618,11 @@ object Parsers {
if in.isNewLine && !(nextIndentWidth < startIndentWidth) then
warning(
if startIndentWidth <= nextIndentWidth then
i"""Line is indented too far to the right, or a `{` is missing before:
i"""Line is indented too far to the right, or a `{` is missing before:
|
|${t.tryToShow}"""
|${t.tryToShow}""".toMessage
else
in.spaceTabMismatchMsg(startIndentWidth, nextIndentWidth),
in.spaceTabMismatchMsg(startIndentWidth, nextIndentWidth).toMessage,
in.next.offset
)
t
Expand All @@ -627,7 +635,7 @@ object Parsers {
if in.isNewLine then
val nextIndentWidth = in.indentWidth(in.next.offset)
if in.currentRegion.indentWidth < nextIndentWidth then
warning(i"Line is indented too far to the right, or a `{` or `:` is missing", in.next.offset)
warning(i"Line is indented too far to the right, or a `{` or `:` is missing".toMessage, in.next.offset)

/* -------- REWRITES ----------------------------------------------------------- */

Expand Down Expand Up @@ -1732,7 +1740,7 @@ object Parsers {
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
else
if sourceVersion.isAtLeast(future) then
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead".toMessage)
patch(source, Span(in.offset, in.offset + 1), "?")
val start = in.skipToken()
typeBounds().withSpan(Span(start, in.lastOffset, start))
Expand Down Expand Up @@ -2171,10 +2179,11 @@ object Parsers {
else Literal(Constant(())) // finally without an expression
}
else {
if (handler.isEmpty) warning(
EmptyCatchAndFinallyBlock(body),
source.atSpan(Span(tryOffset, endOffset(body)))
)
if handler.isEmpty then
report.warning(
EmptyCatchAndFinallyBlock(body),
source.atSpan(Span(tryOffset, endOffset(body)))
)
EmptyTree
}
ParsedTry(body, handler, finalizer)
Expand Down Expand Up @@ -2768,7 +2777,7 @@ object Parsers {
warning(i"""Misleading indentation: this expression forms part of the preceding catch case.
|If this is intended, it should be indented for clarity.
|Otherwise, if the handler is intended to be empty, use a multi-line catch with
|an indented case.""")
|an indented case.""".toMessage)
expr()
else block()
})
Expand Down Expand Up @@ -2989,7 +2998,8 @@ object Parsers {
inBrackets {
if in.token == THIS then
if sourceVersion.isAtLeast(future) then
deprecationWarning("The [this] qualifier will be deprecated in the future; it should be dropped.")
deprecationWarning(
"The [this] qualifier will be deprecated in the future; it should be dropped.".toMessage)
in.nextToken()
mods | Local
else mods.withPrivateWithin(ident().toTypeName)
Expand Down Expand Up @@ -3471,7 +3481,8 @@ object Parsers {
if sourceVersion.isAtLeast(future) then
deprecationWarning(
em"""`= _` has been deprecated; use `= uninitialized` instead.
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""", rhsOffset)
|`uninitialized` can be imported with `scala.compiletime.uninitialized`.""".toMessage,
rhsOffset)
placeholderParams = placeholderParams.tail
atSpan(rhs0.span) { Ident(nme.WILDCARD) }
case rhs0 => rhs0
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object Scanners {

/** signal an error where the input ended in the middle of a token */
def incompleteInputError(msg: String): Unit = {
report.incompleteInputError(msg, sourcePos())
report.incompleteInputError(msg.toMessage, sourcePos())
token = EOF
errOffset = offset
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Parsers._
import util.Spans._
import core._
import Constants._
import Decorators.toMessage
import util.SourceFile
import Utility._

Expand Down Expand Up @@ -379,7 +380,7 @@ object MarkupParsers {
ts(0)
}
},
msg => parser.incompleteInputError(msg)
msg => parser.incompleteInputError(msg.toMessage)
)

/** @see xmlPattern. resynchronizes after successful parse
Expand Down
51 changes: 38 additions & 13 deletions compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,35 @@ object report:
if ctx.settings.verbose.value then echo(msg, pos)

def echo(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
ctx.reporter.report(new Info(msg, pos.sourcePos))
ctx.reporter.report(new Info(msg.toMessage, pos.sourcePos))

private def issueWarning(warning: Warning)(using Context): Unit =
ctx.reporter.report(warning)

def deprecationWarning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
def deprecationWarning(msg: Message, pos: SrcPos)(using Context): Unit =
issueWarning(new DeprecationWarning(msg, pos.sourcePos))

def migrationWarning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
def deprecationWarning(msg: => String, pos: SrcPos)(using Context): Unit =
deprecationWarning(msg.toMessage, pos)

def migrationWarning(msg: Message, pos: SrcPos)(using Context): Unit =
issueWarning(new MigrationWarning(msg, pos.sourcePos))

def uncheckedWarning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
def migrationWarning(msg: => String, pos: SrcPos)(using Context): Unit =
migrationWarning(msg.toMessage, pos)

def uncheckedWarning(msg: Message, pos: SrcPos)(using Context): Unit =
issueWarning(new UncheckedWarning(msg, pos.sourcePos))

def featureWarning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
def uncheckedWarning(msg: => String, pos: SrcPos)(using Context): Unit =
uncheckedWarning(msg.toMessage, pos)

def featureWarning(msg: Message, pos: SrcPos)(using Context): Unit =
issueWarning(new FeatureWarning(msg, pos.sourcePos))

def featureWarning(msg: => String, pos: SrcPos)(using Context): Unit =
featureWarning(msg.toMessage, pos)

def featureWarning(feature: String, featureDescription: => String,
featureUseSite: Symbol, required: Boolean, pos: SrcPos)(using Context): Unit = {
val req = if (required) "needs to" else "should"
Expand All @@ -52,30 +64,43 @@ object report:
|by adding the import clause 'import $fqname'
|or by setting the compiler option -language:$feature.$explain""".stripMargin
if (required) error(msg, pos)
else issueWarning(new FeatureWarning(msg, pos.sourcePos))
else issueWarning(new FeatureWarning(msg.toMessage, pos.sourcePos))
}

def warning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
def warning(msg: Message, pos: SrcPos)(using Context): Unit =
issueWarning(new Warning(msg, addInlineds(pos)))

def error(msg: Message, pos: SrcPos = NoSourcePosition, sticky: Boolean = false)(using Context): Unit =
def warning(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
warning(msg.toMessage, pos)

def error(msg: Message, pos: SrcPos)(using Context): Unit =
val fullPos = addInlineds(pos)
ctx.reporter.report(if (sticky) new StickyError(msg, fullPos) else new Error(msg, fullPos))
ctx.reporter.report(new Error(msg, fullPos))
if ctx.settings.YdebugError.value then Thread.dumpStack()

def error(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
error(msg.toMessage, pos)

def error(ex: TypeError, pos: SrcPos)(using Context): Unit =
error(ex.toMessage, pos, sticky = true)
if ctx.settings.YdebugTypeError.value then ex.printStackTrace()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this removal. Was it intentional? It's the only use of the setting (AFAICT).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was by accident.

val fullPos = addInlineds(pos)
ctx.reporter.report(new StickyError(ex.toMessage, fullPos))
if ctx.settings.YdebugError.value then Thread.dumpStack()

def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition, from: SourceVersion)(using Context): Unit =
def errorOrMigrationWarning(msg: Message, pos: SrcPos, from: SourceVersion)(using Context): Unit =
if sourceVersion.isAtLeast(from) then
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos)
else error(msg, pos)

def gradualErrorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =
def errorOrMigrationWarning(msg: => String, pos: SrcPos, from: SourceVersion)(using Context): Unit =
errorOrMigrationWarning(msg.toMessage, pos, from)

def gradualErrorOrMigrationWarning(msg: Message, pos: SrcPos, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =
if sourceVersion.isAtLeast(errorFrom) then errorOrMigrationWarning(msg, pos, errorFrom)
else if sourceVersion.isAtLeast(warnFrom) then warning(msg, pos)

def gradualErrorOrMigrationWarning(msg: => String, pos: SrcPos, warnFrom: SourceVersion, errorFrom: SourceVersion)(using Context): Unit =
gradualErrorOrMigrationWarning(msg.toMessage, pos, warnFrom, errorFrom)

def restrictionError(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
error(msg.mapMsg("Implementation restriction: " + _), pos)

Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dotty.tools.dotc.util.SourcePosition

import java.util.Optional
import scala.util.chaining._
import core.Decorators.toMessage

object Diagnostic:

Expand All @@ -23,7 +24,8 @@ object Diagnostic:
class Error(
msg: Message,
pos: SourcePosition
) extends Diagnostic(msg, pos, ERROR)
) extends Diagnostic(msg, pos, ERROR):
def this(str: => String, pos: SourcePosition) = this(str.toMessage, pos)

/** A sticky error is an error that should not be hidden by backtracking and
* trying some alternative path. Typically, errors issued after catching
Expand All @@ -46,7 +48,8 @@ object Diagnostic:
class Info(
msg: Message,
pos: SourcePosition
) extends Diagnostic(msg, pos, INFO)
) extends Diagnostic(msg, pos, INFO):
def this(str: => String, pos: SourcePosition) = this(str.toMessage, pos)

abstract class ConditionalWarning(
msg: Message,
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/reporting/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ object Message {
val nonSensicalStartTag: String = "<nonsensical>"
val nonSensicalEndTag: String = "</nonsensical>"

/** This implicit conversion provides a fallback for error messages that have
* not yet been ported to the new scheme. Comment out this `implicit def` to
* see where old errors still exist
*/
implicit def toNoExplanation(str: => String): Message = NoExplanation(str)

def rewriteNotice(what: String, version: SourceVersion | Null = null, options: String = "")(using Context): String =
if !ctx.mode.is(Mode.Interactive) then
val sourceStr = if version != null then i"-source $version" else ""
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dotty.tools.dotc.util.NoSourcePosition
import java.io.{BufferedReader, PrintWriter}
import scala.annotation.internal.sharable
import scala.collection.mutable
import core.Decorators.toMessage

object Reporter {
/** Convert a SimpleReporter into a real Reporter */
Expand Down Expand Up @@ -218,7 +219,7 @@ abstract class Reporter extends interfaces.ReporterResult {
for (settingName, count) <- unreportedWarnings do
val were = if count == 1 then "was" else "were"
val msg = s"there $were ${countString(count, settingName.tail + " warning")}; re-run with $settingName for details"
report(Warning(msg, NoSourcePosition))
report(Warning(msg.toMessage, NoSourcePosition))

/** Print the summary of warnings and errors */
def printSummary()(using Context): Unit = {
Expand Down
Loading