Skip to content

Commit 95ef053

Browse files
committed
Fix #7781: Avoid using nested package definition for Type
Had to remove `sealed` from `Type`
1 parent b28c970 commit 95ef053

File tree

2 files changed

+69
-72
lines changed

2 files changed

+69
-72
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package scala.internal.quoted
2+
3+
/** An Type backed by a tree */
4+
final class TreeType[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quoted.Type[Any] {
5+
override def equals(that: Any): Boolean = that match {
6+
case that: TreeType[_] => typeTree ==
7+
// TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal.
8+
// All scopeId should be equal unless two different runs of the compiler created the trees.
9+
that.typeTree && scopeId == that.scopeId
10+
case _ => false
11+
}
12+
override def hashCode: Int = typeTree.hashCode
13+
override def toString: String = s"Type(<tasty tree>)"
14+
}

library/src/scala/quoted/Type.scala

Lines changed: 55 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,69 @@
1-
package scala
1+
package scala.quoted
22

3-
package quoted {
4-
import scala.quoted.show.SyntaxHighlight
3+
import scala.quoted.show.SyntaxHighlight
54

6-
sealed trait Type[T <: AnyKind] {
7-
type `$splice` = T
5+
/** Quoted type (or kind) `T`
6+
*
7+
* Restriction: only the QuoteContext implementation is allowed to extend this trait.
8+
* Any other implementation will result in an undefined behavior.
9+
*/
10+
trait Type[T <: AnyKind] {
11+
type `$splice` = T
812

9-
/** Show a source code like representation of this type without syntax highlight */
10-
def show(given qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain)
13+
/** Show a source code like representation of this type without syntax highlight */
14+
def show(given qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain)
1115

12-
/** Show a source code like representation of this type */
13-
def show(syntaxHighlight: SyntaxHighlight)(given qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)
16+
/** Show a source code like representation of this type */
17+
def show(syntaxHighlight: SyntaxHighlight)(given qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)
1418

19+
}
20+
21+
/** Some basic type tags, currently incomplete */
22+
object Type {
23+
24+
given UnitTag(given qctx: QuoteContext): Type[Unit] = {
25+
import qctx.tasty.{_, given}
26+
defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]
1527
}
1628

17-
/** Some basic type tags, currently incomplete */
18-
object Type {
19-
20-
given UnitTag(given qctx: QuoteContext): Type[Unit] = {
21-
import qctx.tasty.{_, given}
22-
defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]
23-
}
24-
25-
given BooleanTag(given qctx: QuoteContext): Type[Boolean] = {
26-
import qctx.tasty.{_, given}
27-
defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
28-
}
29-
30-
given ByteTag(given qctx: QuoteContext): Type[Byte] = {
31-
import qctx.tasty.{_, given}
32-
defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]]
33-
}
34-
35-
given CharTag(given qctx: QuoteContext): Type[Char] = {
36-
import qctx.tasty.{_, given}
37-
defn.CharType.seal.asInstanceOf[quoted.Type[Char]]
38-
}
39-
40-
given ShortTag(given qctx: QuoteContext): Type[Short] = {
41-
import qctx.tasty.{_, given}
42-
defn.ShortType.seal.asInstanceOf[quoted.Type[Short]]
43-
}
44-
45-
given IntTag(given qctx: QuoteContext): Type[Int] = {
46-
import qctx.tasty.{_, given}
47-
defn.IntType.seal.asInstanceOf[quoted.Type[Int]]
48-
}
49-
50-
given LongTag(given qctx: QuoteContext): Type[Long] = {
51-
import qctx.tasty.{_, given}
52-
defn.LongType.seal.asInstanceOf[quoted.Type[Long]]
53-
}
54-
55-
given FloatTag(given qctx: QuoteContext): Type[Float] = {
56-
import qctx.tasty.{_, given}
57-
defn.FloatType.seal.asInstanceOf[quoted.Type[Float]]
58-
}
59-
60-
given DoubleTag(given qctx: QuoteContext): Type[Double] = {
61-
import qctx.tasty.{_, given}
62-
defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]]
63-
}
29+
given BooleanTag(given qctx: QuoteContext): Type[Boolean] = {
30+
import qctx.tasty.{_, given}
31+
defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
32+
}
6433

34+
given ByteTag(given qctx: QuoteContext): Type[Byte] = {
35+
import qctx.tasty.{_, given}
36+
defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]]
6537
}
6638

67-
}
39+
given CharTag(given qctx: QuoteContext): Type[Char] = {
40+
import qctx.tasty.{_, given}
41+
defn.CharType.seal.asInstanceOf[quoted.Type[Char]]
42+
}
43+
44+
given ShortTag(given qctx: QuoteContext): Type[Short] = {
45+
import qctx.tasty.{_, given}
46+
defn.ShortType.seal.asInstanceOf[quoted.Type[Short]]
47+
}
48+
49+
given IntTag(given qctx: QuoteContext): Type[Int] = {
50+
import qctx.tasty.{_, given}
51+
defn.IntType.seal.asInstanceOf[quoted.Type[Int]]
52+
}
6853

69-
package internal {
70-
package quoted {
71-
72-
/** An Type backed by a tree */
73-
final class TreeType[Tree](val typeTree: Tree, val scopeId: Int) extends scala.quoted.Type[Any] {
74-
override def equals(that: Any): Boolean = that match {
75-
case that: TreeType[_] => typeTree ==
76-
// TastyTreeExpr are wrappers around trees, therfore they are equals if their trees are equal.
77-
// All scopeId should be equal unless two different runs of the compiler created the trees.
78-
that.typeTree && scopeId == that.scopeId
79-
case _ => false
80-
}
81-
override def hashCode: Int = typeTree.hashCode
82-
override def toString: String = s"Type(<tasty tree>)"
83-
}
54+
given LongTag(given qctx: QuoteContext): Type[Long] = {
55+
import qctx.tasty.{_, given}
56+
defn.LongType.seal.asInstanceOf[quoted.Type[Long]]
57+
}
8458

59+
given FloatTag(given qctx: QuoteContext): Type[Float] = {
60+
import qctx.tasty.{_, given}
61+
defn.FloatType.seal.asInstanceOf[quoted.Type[Float]]
8562
}
63+
64+
given DoubleTag(given qctx: QuoteContext): Type[Double] = {
65+
import qctx.tasty.{_, given}
66+
defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]]
67+
}
68+
8669
}

0 commit comments

Comments
 (0)