Skip to content

Avoid using show or toText before an error is reported #9639

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
Aug 26, 2020
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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,10 @@ object Trees {
def isBackquoted: Boolean = hasAttachment(Backquoted)
}

class SearchFailureIdent[-T >: Untyped] private[ast] (name: Name)(implicit @constructorOnly src: SourceFile)
class SearchFailureIdent[-T >: Untyped] private[ast] (name: Name, expl: => String)(implicit @constructorOnly src: SourceFile)
extends Ident[T](name) {
override def toString: String = s"SearchFailureIdent($name)"
def explanation = expl
override def toString: String = s"SearchFailureIdent($explanation)"
}

/** qualifier.name, or qualifier#name, if qualifier is a type */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
// ------ Creation methods for untyped only -----------------

def Ident(name: Name)(implicit src: SourceFile): Ident = new Ident(name)
def SearchFailureIdent(name: Name)(implicit src: SourceFile): SearchFailureIdent = new SearchFailureIdent(name)
def SearchFailureIdent(name: Name, explanation: => String)(implicit src: SourceFile): SearchFailureIdent = new SearchFailureIdent(name, explanation)
def Select(qualifier: Tree, name: Name)(implicit src: SourceFile): Select = new Select(qualifier, name)
def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit src: SourceFile): Select = new SelectWithSig(qualifier, name, sig)
def This(qual: Ident)(implicit src: SourceFile): This = new This(qual)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ object Denotations {

def requiredMethod(pname: PreName, argTypes: List[Type])(using Context): TermSymbol = {
val name = pname.toTermName
info.member(name).requiredSymbol(i"method", name, this, argTypes) { x =>
info.member(name).requiredSymbol("method", name, this, argTypes) { x =>
x.is(Method) && {
x.info.paramInfoss match {
case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _)
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ object StdNames {
val QUOTE: N = "'"
val TYPE_QUOTE: N = "type_'"
val TRAIT_SETTER_SEPARATOR: N = str.TRAIT_SETTER_SEPARATOR
val AMBIGUOUS: N = "/* ambiguous */"
val MISSING: N = "/* missing */"

// value types (and AnyRef) are all used as terms as well
// as (at least) arguments to the @specialize annotation.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case id: Trees.SearchFailureIdent[?] =>
tree.typeOpt match {
case reason: Implicits.SearchFailureType =>
toText(id.name)
Str(id.explanation)
~ ("summon[" ~ toText(reason.clarify(reason.expectedType)) ~ "]").close
case _ =>
toText(id.name)
Str(id.explanation)
}
case id @ Ident(name) =>
val txt = tree.typeOpt match {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object report:
def featureWarning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
issueWarning(new FeatureWarning(msg, pos.sourcePos))

def featureWarning(feature: String, featureDescription: String,
def featureWarning(feature: String, featureDescription: => String,
featureUseSite: Symbol, required: Boolean, pos: SrcPos)(using Context): Unit = {
val req = if (required) "needs to" else "should"
val fqname = s"scala.language.$feature"
Expand All @@ -56,7 +56,7 @@ object report:
|See the Scala docs for value $fqname for a discussion
|why the feature $req be explicitly enabled.""".stripMargin

val msg = s"""$featureDescription $req be enabled
def msg = s"""$featureDescription $req be enabled
|by adding the import clause 'import $fqname'
|or by setting the compiler option -language:$feature.$explain""".stripMargin
if (required) error(msg, pos)
Expand Down
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import util.NoSourcePosition

import java.io.{ BufferedReader, PrintWriter }


object Reporter {
/** Convert a SimpleReporter into a real Reporter */
def fromSimpleReporter(simple: interfaces.SimpleReporter): Reporter =
Expand Down Expand Up @@ -142,9 +141,14 @@ abstract class Reporter extends interfaces.ReporterResult {
var unreportedWarnings: Map[String, Int] = Map.empty

def report(dia: Diagnostic)(using Context): Unit =
if (!isHidden(dia)) {
val isSummarized = dia match
case dia: ConditionalWarning => !dia.enablingOption.value
case _ => false
if isSummarized // avoid isHidden test for summarized warnings so that message is not forced
|| !isHidden(dia)
then
withMode(Mode.Printing)(doReport(dia))
dia match {
dia match
case dia: ConditionalWarning if !dia.enablingOption.value =>
val key = dia.enablingOption.name
unreportedWarnings =
Expand All @@ -155,8 +159,6 @@ abstract class Reporter extends interfaces.ReporterResult {
_errorCount += 1
case dia: Info => // nothing to do here
// match error if d is something else
}
}

def incomplete(dia: Diagnostic)(using Context): Unit =
incompleteHandler(dia, ctx)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ trait Applications extends Compatibility {
case nil =>
args match {
case arg :: args1 =>
val msg = arg match
def msg = arg match
case untpd.Tuple(Nil)
if applyKind == ApplyKind.InfixTuple && funType.widen.isNullaryMethod =>
i"can't supply unit value with infix notation because nullary $methString takes no arguments; use dotted invocation instead: (...).${methRef.name}()"
Expand Down
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ object Implicits:
object SearchFailure {
def apply(tpe: SearchFailureType)(using Context): SearchFailure = {
val id = tpe match
case tpe: AmbiguousImplicits => i"/* ambiguous: ${tpe.explanation} */"
case _ => "/* missing */"
SearchFailure(untpd.SearchFailureIdent(id.toTermName).withTypeUnchecked(tpe))
case tpe: AmbiguousImplicits =>
untpd.SearchFailureIdent(nme.AMBIGUOUS, s"/* ambiguous: ${tpe.explanation} */")
case _ =>
untpd.SearchFailureIdent(nme.MISSING, "/* missing */")
SearchFailure(id.withTypeUnchecked(tpe))
}
}

Expand Down