Skip to content

Commit 8803595

Browse files
committed
Fix #4395: Handle ## when it is an Ident
1 parent 5dc5a7a commit 8803595

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

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

Lines changed: 17 additions & 23 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"
@@ -54,6 +38,16 @@ class InterceptedMethods extends MiniPhase {
5438
else tree
5539
}
5640

41+
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context): Tree = {
42+
if (tree.symbol.isTerm && (defn.Any_## eq tree.symbol.asTerm)) {
43+
val cls = ctx.owner.ownersIterator.find(_.isClass).get.asClass
44+
val rewrite = poundPoundValue(This(cls))
45+
ctx.log(s"$phaseName rewrote $tree to $rewrite")
46+
rewrite
47+
}
48+
else tree
49+
}
50+
5751
// TODO: add missing cases from scalac
5852
private def poundPoundValue(tree: Tree)(implicit ctx: Context) = {
5953
val s = tree.tpe.widen.typeSymbol

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+
}

0 commit comments

Comments
 (0)