@@ -21,7 +21,7 @@ import dotty.tools.dotc.ast.Trees._
21
21
import dotty .tools .dotc .ast .{untpd , tpd }
22
22
import dotty .tools .dotc .core .Constants .Constant
23
23
import dotty .tools .dotc .core .Types .MethodType
24
- import dotty .tools .dotc .core .Names .Name
24
+ import dotty .tools .dotc .core .Names .{ Name , TermName }
25
25
import scala .collection .mutable .ListBuffer
26
26
import dotty .tools .dotc .core .Denotations .SingleDenotation
27
27
import dotty .tools .dotc .core .SymDenotations .SymDenotation
@@ -64,30 +64,18 @@ class InterceptedMethods extends MiniPhaseTransform {
64
64
else tree
65
65
}
66
66
67
+ // TODO: add missing cases from scalac
67
68
private def poundPoundValue (tree : Tree )(implicit ctx : Context ) = {
68
69
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)
83
70
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)
87
73
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)
91
79
}
92
80
93
81
override def transformApply (tree : Apply )(implicit ctx : Context , info : TransformerInfo ): Tree = {
0 commit comments