Skip to content

Improve compiler messages #4443

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 3 commits into from
May 2, 2018
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
25 changes: 8 additions & 17 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,32 @@ import dotty.tools.dotc.CompilationUnit
import dotty.tools.dotc.ast.Trees.{PackageDef, ValDef}
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.core.Names.TypeName

import scala.collection.mutable
import scala.collection.JavaConverters._
import scala.tools.asm.{ClassVisitor, CustomAttr, FieldVisitor, MethodVisitor}
import scala.tools.asm.CustomAttr
import scala.tools.nsc.backend.jvm._
import dotty.tools.dotc
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.transform.SymUtils._
import dotty.tools.dotc.interfaces
import java.util.Optional

import scala.reflect.ClassTag
import dotty.tools.dotc.core._
import dotty.tools.dotc.sbt.ExtractDependencies
import Periods._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Denotations._
import Decorators._

import Phases._
import java.lang.AssertionError
import java.io.{DataOutputStream, File => JFile}
import java.nio.file.{Files, FileSystem, FileSystems, Path => JPath}
import java.io.DataOutputStream

import dotty.tools.io.{Directory, File, Jar}
import dotty.tools.io.Directory

import scala.tools.asm
import scala.tools.asm.tree._
import dotty.tools.dotc.util.{DotClass, Positions}
import tpd._
import StdNames._
import dotty.tools.io._

class GenBCode extends Phase {
def phaseName: String = "genBCode"
def phaseName: String = GenBCode.name
private val entryPoints = new mutable.HashSet[Symbol]()
def registerEntryPoint(sym: Symbol) = entryPoints += sym

Expand Down Expand Up @@ -80,6 +67,10 @@ class GenBCode extends Phase {
}
}

object GenBCode {
val name: String = "genBCode"
}

class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {

var tree: Tree = _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public enum ErrorMessageID {
JavaSymbolIsNotAValueID,
DoubleDeclarationID,
MatchCaseOnlyNullWarningID,
ImportRenamedTwiceID,
;

public int errorNumber() {
Expand Down
16 changes: 14 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1825,10 +1825,15 @@ object messages {
}
}

case class TailrecNotApplicable(method: Symbol)(implicit ctx: Context)
case class TailrecNotApplicable(symbol: Symbol)(implicit ctx: Context)
extends Message(TailrecNotApplicableID) {
val kind = "Syntax"
val msg = hl"TailRec optimisation not applicable, $method is neither ${"private"} nor ${"final"}."
val symbolKind = symbol.showKind
val msg =
if (symbol.is(Method))
hl"TailRec optimisation not applicable, $symbol is neither ${"private"} nor ${"final"}."
else
hl"TailRec optimisation not applicable, ${symbolKind} isn't a method."
val explanation =
hl"A method annotated ${"@tailrec"} must be declared ${"private"} or ${"final"} so it can't be overridden."
}
Expand Down Expand Up @@ -2105,4 +2110,11 @@ object messages {
}
val explanation = ""
}

case class ImportRenamedTwice(ident: untpd.Ident)(implicit ctx: Context) extends Message(ImportRenamedTwiceID) {
val kind = "Syntax"
val msg: String = s"${ident.show} is renamed twice on the same import line."
val explanation: String = ""
}

}
20 changes: 5 additions & 15 deletions compiler/src/dotty/tools/dotc/transform/CheckStatic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@ package dotty.tools.dotc
package transform

import core._
import Names._
import StdNames.nme
import Types._
import dotty.tools.dotc.transform.MegaPhase._
import ast.Trees._
import Flags._
import Contexts.Context
import Symbols._
import Constants._
import Denotations._
import SymDenotations._
import Decorators.StringInterpolators
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Annotations.ConcreteAnnotation
import scala.collection.mutable
import DenotTransformers._
import Names.Name
import NameOps._
import Decorators._
import TypeUtils._
import reporting.diagnostic.messages.{MissingCompanionForStatic, StaticFieldsOnlyAllowedInObjects}

/** A transformer that check that requirements of Static fields\methods are implemented:
Expand All @@ -39,7 +25,7 @@ import reporting.diagnostic.messages.{MissingCompanionForStatic, StaticFieldsOnl
class CheckStatic extends MiniPhase {
import ast.tpd._

override def phaseName = "checkStatic"
override def phaseName = CheckStatic.name

override def transformTemplate(tree: tpd.Template)(implicit ctx: Context): tpd.Tree = {
val defns = tree.body.collect{case t: ValOrDefDef => t}
Expand Down Expand Up @@ -91,3 +77,7 @@ class CheckStatic extends MiniPhase {
} else tree
}
}

object CheckStatic {
val name = "checkStatic"
}
17 changes: 6 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ package dotty.tools.dotc
package transform

import dotty.tools.dotc.ast.{Trees, tpd, untpd}
import scala.collection.{ mutable, immutable }
import ValueClasses._
import scala.annotation.tailrec
import scala.collection.mutable
import core._
import typer.ErrorReporting._
import typer.Checking
import Types._, Contexts._, Constants._, Names._, NameOps._, Flags._, DenotTransformers._
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Scopes._, Denotations._
import util.Positions._
import Types._, Contexts._, Names._, Flags._, DenotTransformers._
import SymDenotations._, StdNames._, Annotations._, Trees._
import Decorators._
import config.Printers.typr
import Symbols._, TypeUtils._, SymUtils._
import reporting.diagnostic.messages.{NotAMember, SuperCallsNotAllowedInline}
import Symbols._, SymUtils._
import reporting.diagnostic.messages.{ImportRenamedTwice, NotAMember, SuperCallsNotAllowedInline}

object PostTyper {
val name = "posttyper"
Expand Down Expand Up @@ -293,7 +288,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
if (name != nme.WILDCARD && !exprTpe.member(name).exists && !exprTpe.member(name.toTypeName).exists)
ctx.error(NotAMember(exprTpe, name, "value"), ident.pos)
if (seen(ident.name))
ctx.error(s"${ident.show} is renamed twice", ident.pos)
ctx.error(ImportRenamedTwice(ident), ident.pos)
seen += ident.name
}
selectors.foreach {
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/TailRec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import ast.{TreeTypeMap, tpd}
import core._
import Contexts.Context
import Decorators._
import DenotTransformers.IdentityDenotTransformer
import Denotations.SingleDenotation
import Symbols._
import Types._
import NameKinds.TailLabelName
Expand Down Expand Up @@ -161,9 +159,6 @@ class TailRec extends MiniPhase with FullParameterization {
case d: DefDef if d.symbol.hasAnnotation(defn.TailrecAnnot) || methodsWithInnerAnnots.contains(d.symbol) =>
ctx.error(TailrecNotApplicable(sym), sym.pos)
d
case d if d.symbol.hasAnnotation(defn.TailrecAnnot) || methodsWithInnerAnnots.contains(d.symbol) =>
ctx.error("TailRec optimisation not applicable, not a method", sym.pos)
d
case _ => tree
}

Expand Down
13 changes: 4 additions & 9 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,25 @@ import ast._
import Contexts._
import Types._
import Flags._
import Denotations._
import Names._
import StdNames._
import NameOps._
import Symbols._
import Trees._
import TreeInfo._
import ProtoTypes._
import Constants._
import Scopes._
import CheckRealizable._
import ErrorReporting.errorTree

import annotation.unchecked
import util.Positions._
import util.Stats
import util.common._
import transform.SymUtils._
import Decorators._
import Uniques._
import ErrorReporting.{err, errorType}
import config.Printers.typr
import NameKinds.DefaultGetterName

import collection.mutable
import SymDenotations.{NoCompleter, NoDenotation}
import dotty.tools.dotc.reporting.diagnostic.{ErrorMessageID, Message}
import dotty.tools.dotc.reporting.diagnostic.Message
import dotty.tools.dotc.reporting.diagnostic.messages._
import dotty.tools.dotc.transform.ValueClasses._

Expand Down Expand Up @@ -358,6 +350,9 @@ object Checking {
fail(AbstractOverrideOnlyInTraits(sym))
if (sym.is(Trait) && sym.is(Final))
fail(TraitsMayNotBeFinal(sym))
// Skip ModuleVal since the annotation will also be on the ModuleClass
if (sym.hasAnnotation(defn.TailrecAnnot) && !sym.is(Method | ModuleVal))
fail(TailrecNotApplicable(sym))
if (sym.hasAnnotation(defn.NativeAnnot)) {
if (!sym.is(Deferred))
fail(NativeMembersMayNotHaveImplementation(sym))
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/FrontEnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ast.Trees._

class FrontEnd extends Phase {

override def phaseName = "frontend"
override def phaseName = FrontEnd.name
override def isTyper = true
import ast.tpd

Expand Down Expand Up @@ -103,3 +103,7 @@ class FrontEnd extends Phase {
typeCheck
}
}

object FrontEnd {
val name = "frontend"
}
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package typer

import transform._
import core._
import config._
import Symbols._, SymDenotations._, Types._, Contexts._, Decorators._, Flags._, Names._, NameOps._
import StdNames._, Denotations._, Scopes._, Constants.Constant, SymUtils._
import Symbols._, Types._, Contexts._, Flags._, Names._, NameOps._
import StdNames._, Denotations._, SymUtils._
import NameKinds.DefaultGetterName
import Annotations._
import util.Positions._
Expand All @@ -16,17 +15,17 @@ import Trees._
import MegaPhase._
import config.Printers.{checks, noPrinter}
import util.DotClass
import scala.util.{Try, Success, Failure}
import config.{ScalaVersion, NoScalaVersion}
import scala.util.Failure
import config.NoScalaVersion
import Decorators._
import typer.ErrorReporting._
import DenotTransformers._

object RefChecks {
import tpd._
import reporting.diagnostic.Message
import reporting.diagnostic.messages._

val name = "refchecks"

private val defaultMethodFilter = new NameFilter {
def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean = name.is(DefaultGetterName)
}
Expand Down Expand Up @@ -910,7 +909,7 @@ class RefChecks extends MiniPhase { thisPhase =>
import reporting.diagnostic.messages.ForwardReferenceExtendsOverDefinition
import dotty.tools.dotc.reporting.diagnostic.messages.UnboundPlaceholderParameter

override def phaseName: String = "refchecks"
override def phaseName: String = RefChecks.name

// Needs to run after ElimRepeated for override checks involving varargs methods
override def runsAfter = Set(ElimRepeated.name)
Expand Down
Loading