Skip to content

Commit 8d2ee65

Browse files
authored
Merge pull request #7784 from dotty-staging/fix-#7781
Fix #7781: Avoid using nested package definition
2 parents fa9a48e + 7af199d commit 8d2ee65

File tree

9 files changed

+329
-334
lines changed

9 files changed

+329
-334
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import dotty.tools.dotc.core.tasty.TreePickler.Hole
1515
import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter }
1616
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
1717
import dotty.tools.dotc.quoted.QuoteContext
18-
import dotty.tools.dotc.tastyreflect.ReflectionImpl
18+
import dotty.tools.dotc.tastyreflect.{ReflectionImpl, TastyTreeExpr, TreeType}
1919

2020
import dotty.tools.tasty.TastyString
2121

@@ -38,14 +38,14 @@ object PickledQuotes {
3838

3939
/** Transform the expression into its fully spliced Tree */
4040
def quotedExprToTree[T](expr: quoted.Expr[T])(implicit ctx: Context): Tree = {
41-
val expr1 = expr.asInstanceOf[TastyTreeExpr[Tree]]
41+
val expr1 = expr.asInstanceOf[TastyTreeExpr]
4242
QuoteContext.checkScopeId(expr1.scopeId)
4343
healOwner(expr1.tree)
4444
}
4545

4646
/** Transform the expression into its fully spliced TypeTree */
4747
def quotedTypeToTree(tpe: quoted.Type[?])(implicit ctx: Context): Tree = {
48-
val tpe1 = tpe.asInstanceOf[TreeType[Tree]]
48+
val tpe1 = tpe.asInstanceOf[TreeType]
4949
QuoteContext.checkScopeId(tpe1.scopeId)
5050
healOwner(tpe1.typeTree)
5151
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import dotty.tools.dotc.quoted.QuoteContext
3838
import dotty.tools.tasty.TastyFormat._
3939

4040
import scala.quoted
41-
import scala.internal.quoted.{TastyTreeExpr, TreeType}
41+
import dotty.tools.dotc.tastyreflect.{TastyTreeExpr, TreeType}
4242
import scala.annotation.constructorOnly
4343
import scala.annotation.internal.sharable
4444

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
3535
//
3636

3737
def unpickleExpr(repr: Unpickler.PickledQuote, args: Unpickler.PickledExprArgs): scala.quoted.Expr[?] =
38-
new scala.internal.quoted.TastyTreeExpr(PickledQuotes.unpickleExpr(repr, args), compilerId)
38+
new TastyTreeExpr(PickledQuotes.unpickleExpr(repr, args), compilerId)
3939

4040
def unpickleType(repr: Unpickler.PickledQuote, args: Unpickler.PickledTypeArgs): scala.quoted.Type[?] =
41-
new scala.internal.quoted.TreeType(PickledQuotes.unpickleType(repr, args), compilerId)
41+
new TreeType(PickledQuotes.unpickleType(repr, args), compilerId)
4242

4343
//
4444
// CONTEXT
@@ -1779,7 +1779,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
17791779
/** Convert `Term` to an `quoted.Expr[Any]` */
17801780
def QuotedExpr_seal(self: Term)(given ctx: Context): scala.quoted.Expr[Any] = self.tpe.widen match {
17811781
case _: Types.MethodType | _: Types.PolyType => throw new Exception("Cannot seal a partially applied Term. Try eta-expanding the term first.")
1782-
case _ => new scala.internal.quoted.TastyTreeExpr(self, compilerId)
1782+
case _ => new TastyTreeExpr(self, compilerId)
17831783
}
17841784

17851785
/** Checked cast to a `quoted.Expr[U]` */
@@ -1799,7 +1799,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
17991799
/** Convert `Type` to an `quoted.Type[?]` */
18001800
def QuotedType_seal(self: Type)(given ctx: Context): scala.quoted.Type[?] = {
18011801
val dummySpan = ctx.owner.span // FIXME
1802-
new scala.internal.quoted.TreeType(tpd.TypeTree(self).withSpan(dummySpan), compilerId)
1802+
new TreeType(tpd.TypeTree(self).withSpan(dummySpan), compilerId)
18031803
}
18041804

18051805
//
@@ -1988,4 +1988,3 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
19881988

19891989
private def compilerId: Int = rootContext.outersIterator.toList.last.hashCode()
19901990
}
1991-
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
import dotty.tools.dotc.ast.tpd.Tree
4+
5+
/** An Expr backed by a tree. Only the current compiler trees are allowed.
6+
*
7+
* These expressions are used for arguments of macros. They contain and actual tree
8+
* from the program that is being expanded by the macro.
9+
*
10+
* May contain references to code defined outside this TastyTreeExpr instance.
11+
*/
12+
final class TastyTreeExpr(val tree: Tree, val scopeId: Int) extends scala.quoted.Expr[Any] {
13+
override def equals(that: Any): Boolean = that match {
14+
case that: TastyTreeExpr =>
15+
// TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal.
16+
// All scopeId should be equal unless two different runs of the compiler created the trees.
17+
tree == that.tree && scopeId == that.scopeId
18+
case _ => false
19+
}
20+
override def hashCode: Int = tree.hashCode
21+
override def toString: String = s"Expr(<tasty tree>)"
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dotty.tools.dotc.tastyreflect
2+
3+
import dotty.tools.dotc.ast.tpd.Tree
4+
5+
/** An Type backed by a tree */
6+
final class TreeType(val typeTree: Tree, val scopeId: Int) extends scala.quoted.Type[Any] {
7+
override def equals(that: Any): Boolean = that match {
8+
case that: TreeType => typeTree ==
9+
// TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal.
10+
// All scopeId should be equal unless two different runs of the compiler created the trees.
11+
that.typeTree && scopeId == that.scopeId
12+
case _ => false
13+
}
14+
override def hashCode: Int = typeTree.hashCode
15+
override def toString: String = s"Type(<tasty tree>)"
16+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import dotty.tools.dotc.core.Types._
1717
import dotty.tools.dotc.core.Symbols._
1818
import dotty.tools.dotc.core.{NameKinds, TypeErasure}
1919
import dotty.tools.dotc.core.Constants.Constant
20-
import dotty.tools.dotc.tastyreflect.ReflectionImpl
20+
import dotty.tools.dotc.tastyreflect.{ReflectionImpl, TastyTreeExpr, TreeType}
2121

2222
import scala.util.control.NonFatal
2323
import dotty.tools.dotc.util.SourcePosition
@@ -246,10 +246,10 @@ object Splicer {
246246
}
247247

248248
private def interpretQuote(tree: Tree)(implicit env: Env): Object =
249-
new scala.internal.quoted.TastyTreeExpr(Inlined(EmptyTree, Nil, tree).withSpan(tree.span), QuoteContext.scopeId)
249+
new TastyTreeExpr(Inlined(EmptyTree, Nil, tree).withSpan(tree.span), QuoteContext.scopeId)
250250

251251
private def interpretTypeQuote(tree: Tree)(implicit env: Env): Object =
252-
new scala.internal.quoted.TreeType(tree, QuoteContext.scopeId)
252+
new TreeType(tree, QuoteContext.scopeId)
253253

254254
private def interpretLiteral(value: Any)(implicit env: Env): Object =
255255
value.asInstanceOf[Object]

0 commit comments

Comments
 (0)