Skip to content

Commit f1853c7

Browse files
Remove extra .toTermNames
1 parent 0e5b505 commit f1853c7

File tree

8 files changed

+57
-16
lines changed

8 files changed

+57
-16
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
365365
def getAnnotPickle(jclassName: String, sym: Symbol): Option[Annotation] = None
366366

367367

368-
def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname.toTermName)
368+
def getRequiredClass(fullname: String): Symbol = ctx.requiredClass(fullname)
369369

370370
def getClassIfDefined(fullname: String): Symbol = NoSymbol // used only for android. todo: implement
371371

@@ -375,12 +375,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
375375
}
376376

377377
def requiredClass[T](implicit evidence: ClassTag[T]): Symbol =
378-
ctx.requiredClass(erasureString(evidence.runtimeClass).toTermName)
378+
ctx.requiredClass(erasureString(evidence.runtimeClass))
379379

380380
def requiredModule[T](implicit evidence: ClassTag[T]): Symbol = {
381381
val moduleName = erasureString(evidence.runtimeClass)
382382
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
383-
ctx.requiredModule(className.toTermName)
383+
ctx.requiredModule(className)
384384
}
385385

386386

@@ -1193,8 +1193,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11931193
val arity = field.meth.tpe.widenDealias.paramTypes.size - _1.size
11941194
val returnsUnit = field.meth.tpe.widenDealias.resultType.classSymbol == UnitClass
11951195
if (returnsUnit)
1196-
ctx.requiredClass(("scala.compat.java8.JProcedure" + arity).toTermName)
1197-
else ctx.requiredClass(("scala.compat.java8.JFunction" + arity).toTermName)
1196+
ctx.requiredClass(("scala.compat.java8.JProcedure" + arity))
1197+
else ctx.requiredClass(("scala.compat.java8.JFunction" + arity))
11981198
}
11991199
}
12001200
}

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Definitions {
201201
lazy val OpsPackageVal = ctx.newCompletePackageSymbol(RootClass, nme.OPS_PACKAGE).entered
202202
lazy val OpsPackageClass = OpsPackageVal.moduleClass.asClass
203203

204-
lazy val ScalaPackageVal = ctx.requiredPackage("scala")
204+
lazy val ScalaPackageVal = ctx.requiredPackage(nme.scala_)
205205
lazy val ScalaMathPackageVal = ctx.requiredPackage("scala.math")
206206
lazy val ScalaPackageClass = {
207207
val cls = ScalaPackageVal.moduleClass.asClass
@@ -212,8 +212,8 @@ class Definitions {
212212
cls
213213
}
214214
lazy val ScalaPackageObjectRef = ctx.requiredModuleRef("scala.package")
215-
lazy val JavaPackageVal = ctx.requiredPackage("java")
216-
lazy val JavaLangPackageVal = ctx.requiredPackage("java.lang")
215+
lazy val JavaPackageVal = ctx.requiredPackage(nme.java)
216+
lazy val JavaLangPackageVal = ctx.requiredPackage(jnme.JavaLang)
217217
// fundamental modules
218218
lazy val SysPackage = ctx.requiredModule("scala.sys.package")
219219
lazy val Sys_errorR = SysPackage.moduleClass.requiredMethodRef(nme.error)
@@ -339,11 +339,11 @@ class Definitions {
339339

340340
lazy val Predef_ConformsR = ScalaPredefModule.requiredClass("<:<").typeRef
341341
def Predef_Conforms(implicit ctx: Context) = Predef_ConformsR.symbol
342-
lazy val Predef_conformsR = ScalaPredefModule.requiredMethodRef("$conforms")
342+
lazy val Predef_conformsR = ScalaPredefModule.requiredMethodRef(nme.conforms_)
343343
def Predef_conforms(implicit ctx: Context) = Predef_conformsR.symbol
344-
lazy val Predef_classOfR = ScalaPredefModule.requiredMethodRef("classOf")
344+
lazy val Predef_classOfR = ScalaPredefModule.requiredMethodRef(nme.classOf)
345345
def Predef_classOf(implicit ctx: Context) = Predef_classOfR.symbol
346-
lazy val Predef_undefinedR = ScalaPredefModule.requiredMethodRef("???")
346+
lazy val Predef_undefinedR = ScalaPredefModule.requiredMethodRef(nme.???)
347347
def Predef_undefined(implicit ctx: Context) = Predef_undefinedR.symbol
348348
// The set of all wrap{X, Ref}Array methods, where X is a value type
349349
val Predef_wrapArray = new PerRun[collection.Set[Symbol]]({ implicit ctx =>

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ object StdNames {
393393
val ClassManifestFactory: N = "ClassManifestFactory"
394394
val classOf: N = "classOf"
395395
val clone_ : N = "clone"
396-
// val conforms : N = "conforms" // Dotty deviation: no special treatment of conforms, so the occurrence of the name here would cause to unintended implicit shadowing. Should find a less common name for it in Predef.
396+
val conforms_ : N = "$conforms"
397397
val copy: N = "copy"
398398
val currentMirror: N = "currentMirror"
399399
val create: N = "create"

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
4949
def printNat() = print(Yellow(" " + readNat()).show)
5050
def printName() = {
5151
val idx = readNat()
52-
print(nameColor(" " + idx + " [" + nameRefToString(NameRef(idx)) + "]").show)
52+
print(nameColor(" " + idx + " [" + nameRefToString(NameRef(idx)) + "]"))
5353
}
5454
def printTree(): Unit = {
5555
newLine()

sbt-dotty/sbt-test/sbt-dotty/compiler-plugin/plugin/DivideZero.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DivideZero extends PluginPhase with StandardPlugin {
2626

2727
private def isNumericDivide(sym: Symbol)(implicit ctx: Context): Boolean = {
2828
def test(tpe: String): Boolean =
29-
(sym.owner eq ctx.requiredClass(tpe.toTermName)) && sym.name.show == "/"
29+
(sym.owner eq ctx.requiredClass(tpe)) && sym.name.show == "/"
3030

3131
test("scala.Int") || test("scala.Long") || test("scala.Short") || test("scala.Float") || test("scala.Double")
3232
}

tests/plugins/neg/divideZero-research/plugin_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DivideZero extends MiniPhase with ResearchPlugin {
2323

2424
private def isNumericDivide(sym: Symbol)(implicit ctx: Context): Boolean = {
2525
def test(tpe: String): Boolean =
26-
(sym.owner eq ctx.requiredClass(tpe.toTermName)) && sym.name == nme.DIV
26+
(sym.owner eq ctx.requiredClass(tpe)) && sym.name == nme.DIV
2727

2828
test("scala.Int") || test("scala.Long") || test("scala.Short") || test("scala.Float") || test("scala.Double")
2929
}

tests/plugins/neg/divideZero/plugin_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DivideZero extends PluginPhase with StandardPlugin {
2424

2525
private def isNumericDivide(sym: Symbol)(implicit ctx: Context): Boolean = {
2626
def test(tpe: String): Boolean =
27-
(sym.owner eq ctx.requiredClass(tpe.toTermName)) && sym.name == nme.DIV
27+
(sym.owner eq ctx.requiredClass(tpe)) && sym.name == nme.DIV
2828

2929
test("scala.Int") || test("scala.Long") || test("scala.Short") || test("scala.Float") || test("scala.Double")
3030
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import dotty.tools.dotc._
2+
import core._
3+
import Contexts.Context
4+
import plugins.Plugin
5+
import Phases.Phase
6+
import ast.tpd
7+
import transform.MegaPhase.MiniPhase
8+
import Decorators._
9+
import Symbols.Symbol
10+
import Constants.Constant
11+
import StdNames._
12+
13+
14+
class DivideZero extends MiniPhase with Plugin {
15+
val name: String = "divideZero"
16+
override val description: String = "divide by zero check"
17+
18+
val phaseName = name
19+
20+
override val research = true
21+
22+
override def init(options: List[String], phases: List[List[Phase]])(implicit ctx: Context): List[List[Phase]] = {
23+
val (before, after) = phases.span(ps => !ps.exists(_.phaseName == "pickler"))
24+
before ++ (List(this) :: after)
25+
}
26+
27+
private def isNumericDivide(sym: Symbol)(implicit ctx: Context): Boolean = {
28+
def test(tpe: String): Boolean =
29+
(sym.owner eq ctx.requiredClass(tpe)) && sym.name == nme.DIV
30+
31+
test("scala.Int") || test("scala.Long") || test("scala.Short") || test("scala.Float") || test("scala.Double")
32+
}
33+
34+
override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree = tree match {
35+
case tpd.Apply(fun, tpd.Literal(Constants.Constant(v)) :: Nil) if isNumericDivide(fun.symbol) && v == 0 =>
36+
ctx.warning("divide by zero", tree.pos)
37+
tree
38+
case _ =>
39+
tree
40+
}
41+
}

0 commit comments

Comments
 (0)