Skip to content

Commit f2814c3

Browse files
Merge pull request #4474 from dotty-staging/fix-#4395
Fix #4395: Handle ## when it is an Ident
2 parents 89ff080 + 02cbf1f commit f2814c3

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

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

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
11
package dotty.tools.dotc
22
package transform
33

4-
import MegaPhase._
5-
import core.Denotations._
6-
import core.SymDenotations._
7-
import core.Contexts._
8-
import core.Types._
9-
import ast.Trees._
10-
import ast.tpd.{Apply, Tree, cpy}
11-
import dotty.tools.dotc.ast.tpd
12-
import scala.collection.mutable
13-
import dotty.tools.dotc._
14-
import core._
15-
import Contexts._
16-
import Symbols._
17-
import Decorators._
18-
import NameOps._
194
import dotty.tools.dotc.ast.Trees._
20-
import dotty.tools.dotc.ast.{untpd, tpd}
5+
import dotty.tools.dotc.ast.tpd
216
import dotty.tools.dotc.core.Constants.Constant
22-
import dotty.tools.dotc.core.Types.MethodType
23-
import dotty.tools.dotc.core.Names.{ Name, TermName }
24-
import scala.collection.mutable.ListBuffer
25-
import dotty.tools.dotc.core.Denotations.SingleDenotation
26-
import dotty.tools.dotc.core.SymDenotations.SymDenotation
27-
import StdNames._
28-
import Phases.Phase
7+
import dotty.tools.dotc.core.Contexts._
8+
import dotty.tools.dotc.core.Names.TermName
9+
import dotty.tools.dotc.core.StdNames._
10+
import dotty.tools.dotc.core.Symbols._
11+
import dotty.tools.dotc.core.Types._
12+
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
2913

3014
object InterceptedMethods {
3115
val name = "intercepted"
@@ -45,9 +29,19 @@ class InterceptedMethods extends MiniPhase {
4529
override def phaseName: String = InterceptedMethods.name
4630

4731
// this should be removed if we have guarantee that ## will get Apply node
48-
override def transformSelect(tree: tpd.Select)(implicit ctx: Context): Tree = {
49-
if (tree.symbol.isTerm && (defn.Any_## eq tree.symbol.asTerm)) {
50-
val rewrite = poundPoundValue(tree.qualifier)
32+
override def transformSelect(tree: tpd.Select)(implicit ctx: Context): Tree =
33+
transformRefTree(tree)
34+
35+
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context): Tree =
36+
transformRefTree(tree)
37+
38+
private def transformRefTree(tree: RefTree)(implicit ctx: Context): Tree = {
39+
if (tree.symbol.isTerm && (defn.Any_## eq tree.symbol)) {
40+
val qual = tree match {
41+
case id: Ident => tpd.desugarIdentPrefix(id)
42+
case sel: Select => sel.qualifier
43+
}
44+
val rewrite = poundPoundValue(qual)
5145
ctx.log(s"$phaseName rewrote $tree to $rewrite")
5246
rewrite
5347
}

tests/pos/i4395.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
val res0 = ##
3+
val res1 = this.##
4+
}

tests/pos/i4395b.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
val res0 = ==(null)
3+
val res1 = !=(null)
4+
val res4 = getClass
5+
}

0 commit comments

Comments
 (0)