Skip to content

Commit 84adea0

Browse files
committed
Fix issue with anyHash in ScalaRuntime
1 parent 2efc0dd commit 84adea0

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,15 @@ object StdNames {
325325
val ArrayAnnotArg: N = "ArrayAnnotArg"
326326
val Constant: N = "Constant"
327327
val ConstantType: N = "ConstantType"
328+
val doubleHash: N = "doubleHash"
328329
val ExistentialTypeTree: N = "ExistentialTypeTree"
329330
val Flag : N = "Flag"
331+
val floatHash: N = "floatHash"
330332
val Ident: N = "Ident"
331333
val Import: N = "Import"
332334
val Literal: N = "Literal"
333335
val LiteralAnnotArg: N = "LiteralAnnotArg"
336+
val longHash: N = "longHash"
334337
val Modifiers: N = "Modifiers"
335338
val NestedAnnotArg: N = "NestedAnnotArg"
336339
val NoFlags: N = "NoFlags"
@@ -353,6 +356,7 @@ object StdNames {
353356
val UNIT : N = "UNIT"
354357
val add_ : N = "add"
355358
val annotation: N = "annotation"
359+
val anyHash: N = "anyHash"
356360
val anyValClass: N = "anyValClass"
357361
val append: N = "append"
358362
val apply: N = "apply"

compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import dotty.tools.dotc.ast.Trees._
2121
import dotty.tools.dotc.ast.{untpd, tpd}
2222
import dotty.tools.dotc.core.Constants.Constant
2323
import dotty.tools.dotc.core.Types.MethodType
24-
import dotty.tools.dotc.core.Names.Name
24+
import dotty.tools.dotc.core.Names.{ Name, TermName }
2525
import scala.collection.mutable.ListBuffer
2626
import dotty.tools.dotc.core.Denotations.SingleDenotation
2727
import dotty.tools.dotc.core.SymDenotations.SymDenotation
@@ -64,30 +64,18 @@ class InterceptedMethods extends MiniPhaseTransform {
6464
else tree
6565
}
6666

67+
// TODO: add missing cases from scalac
6768
private def poundPoundValue(tree: Tree)(implicit ctx: Context) = {
6869
val s = tree.tpe.widen.typeSymbol
69-
if (s == defn.NullClass) Literal(Constant(0))
70-
else {
71-
// Since we are past typer, we need to avoid creating trees carrying
72-
// overloaded types. This logic is custom (and technically incomplete,
73-
// although serviceable) for def hash. What is really needed is for
74-
// the overloading logic presently hidden away in a few different
75-
// places to be properly exposed so we can just call "resolveOverload"
76-
// after typer. Until then:
77-
78-
def alts = defn.ScalaRuntimeModule.info.member(nme.hash_)
79-
80-
// if tpe is a primitive value type, alt1 will match on the exact value,
81-
// taking in account that null.asInstanceOf[Int] == 0
82-
def alt1 = alts.suchThat(_.info.firstParamTypes.head =:= tree.tpe.widen)
8370

84-
// otherwise alt2 will match. alt2 also knows how to handle 'null' runtime value
85-
def alt2 = defn.ScalaRuntimeModule.info.member(nme.hash_)
86-
.suchThat(_.info.firstParamTypes.head.typeSymbol == defn.AnyClass)
71+
def staticsCall(methodName: TermName): Tree =
72+
ref(defn.staticsMethodRef(methodName)).appliedTo(tree)
8773

88-
Ident((if (s.isNumericValueClass) alt1 else alt2).termRef)
89-
.appliedTo(tree)
90-
}
74+
if (s == defn.NullClass) Literal(Constant(0))
75+
else if (s == defn.DoubleClass) staticsCall(nme.doubleHash)
76+
else if (s == defn.LongClass) staticsCall(nme.longHash)
77+
else if (s == defn.FloatClass) staticsCall(nme.floatHash)
78+
else staticsCall(nme.anyHash)
9179
}
9280

9381
override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = {

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ object Build {
469469

470470
// get libraries onboard
471471
libraryDependencies ++= Seq("com.typesafe.sbt" % "sbt-interface" % sbtVersion.value,
472-
("org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6").withDottyCompat(),
472+
("org.scala-lang.modules" %% "scala-xml" % "1.0.6").withDottyCompat(),
473473
"com.novocode" % "junit-interface" % "0.11" % "test",
474474
"org.scala-lang" % "scala-library" % scalacVersion % "test"),
475475

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ object DottyPlugin extends AutoPlugin {
5151
moduleID.crossVersion match {
5252
case _: CrossVersion.Binary =>
5353
moduleID.cross(CrossVersion.binaryMapped {
54+
// TODO: this will break on release of >= 0.4
55+
case version if version.startsWith("0.3") => "2.12"
5456
case version if version.startsWith("0.") => "2.11"
5557
case version => version
5658
})

0 commit comments

Comments
 (0)