Skip to content

Commit 7fa845c

Browse files
committed
Fix typetree TypeBounds
1 parent 8c15881 commit 7fa845c

File tree

9 files changed

+103
-8
lines changed

9 files changed

+103
-8
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dotty.tools.dotc.tasty.internal
2+
3+
import dotty.tools.dotc.core.Contexts.Context
4+
import dotty.tools.dotc.core.Types
5+
6+
import scala.tasty.types
7+
8+
object MaybeType {
9+
10+
def apply(tpe: Types.Type)(implicit ctx: Context): types.MaybeType = tpe match {
11+
case tpe: Types.TypeBounds => TypeBounds(tpe)
12+
case _ => Type(tpe)
13+
}
14+
15+
}

compiler/src/dotty/tools/dotc/tasty/internal/Type.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object Type {
4747

4848
def unapplyRefinement(arg: types.MaybeType): Option[types.Refinement.Data] = arg match {
4949
case Impl(Types.RefinedType(parent, name, info), ctx) =>
50-
Some((Type(parent)(ctx), if (name.isTermName) TermName(name.asTermName) else TypeName(name.asTypeName), Type(info)(ctx)))
50+
Some((Type(parent)(ctx), if (name.isTermName) TermName(name.asTermName) else TypeName(name.asTypeName), MaybeType(info)(ctx)))
5151
case _ => None
5252
}
5353

@@ -88,6 +88,9 @@ object Type {
8888
}
8989

9090
private case class Impl(arg: Types.Type, ctx: Context) extends types.Type {
91+
92+
assert(!arg.isInstanceOf[Types.TypeBounds])
93+
9194
override def toString: String = {
9295
import Toolbox.extractor
9396
// FIXME

compiler/src/dotty/tools/dotc/tasty/internal/TypeBounds.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import scala.tasty.types
88

99
object TypeBounds {
1010

11-
// TODO make sure all extractors are tested
12-
1311
def apply(bounds: Types.TypeBounds)(implicit ctx: Context): types.TypeBounds = Impl(bounds, ctx)
1412

1513
def unapplyTypeBounds(tpe: types.MaybeType): Option[types.TypeBounds.Data] = tpe match {

compiler/src/dotty/tools/dotc/tasty/internal/TypeTree.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object TypeTree {
7070

7171
private case class Impl(tree: Tree, ctx: Context) extends typetrees.TypeTree with Positioned {
7272

73-
def tpe: types.Type = Type(tree.tpe)(ctx)
73+
def tpe: types.MaybeType = MaybeType(tree.tpe)(ctx)
7474

7575
override def toString: String = {
7676
import Toolbox.extractor

library/src/scala/tasty/types/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package object types {
2626
}
2727

2828
object Refinement {
29-
type Data = (Type, names.Name, Type)
29+
type Data = (Type, names.Name, MaybeType /* Type | TypeBounds */)
3030
def unapply(arg: MaybeType)(implicit toolbox: Toolbox): Option[Data] = toolbox.unapplyRefinement(arg)
3131
}
3232

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package scala.tasty.typetrees
22

33
import scala.tasty.Positioned
4-
import scala.tasty.types.Type
4+
import scala.tasty.types.MaybeType
55

66
/** Trees denoting types */
77
trait TypeTree extends Positioned {
8-
def tpe: Type
8+
def tpe: MaybeType
99
}

tests/pos/tasty/definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object definitions {
9292

9393
/** Trees denoting types */
9494
enum TypeTree extends Positioned {
95-
def tpe: Type = ???
95+
def tpe: Type | TypeBounds = ??? // TODO should we extract TypeBounds like in types?
9696
case Synthetic()
9797
case Ident(name: TypeName, override val tpe: Type)
9898
case Select(prefix: Term, name: TypeName)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
NameRef(Int, ###)
2+
3+
###
4+
5+
TypeBounds(NameRef(Nothing, ###), NameRef(Any, ###))
6+
7+
NameRef(Nothing, ###)
8+
9+
NameRef(Any, ###)
10+
11+
###
12+
13+
TypeBounds(NameRef(Int, ###), NameRef(Int, ###))
14+
15+
NameRef(Int, ###)
16+
17+
NameRef(Int, ###)
18+
19+
###
20+
21+
NameRef(Unit, ###)
22+
23+
NameRef(Object, ###)
24+
25+
TypeBounds(NameRef(Nothing, ###), NameRef(Any, ###))
26+
27+
NameRef(Nothing, ###)
28+
29+
NameRef(Any, ###)
30+
31+
Refinement(###, X, TypeBounds(NameRef(String, NameRef(Predef, ###)), NameRef(String, NameRef(Predef, ###))))
32+
33+
NameRef(Unit, ###)
34+
35+
###
36+
37+
NameRef(String, NameRef(Predef, ###))
38+
39+
###
40+
41+
Refinement(###, X, TypeBounds(NameRef(String, NameRef(Predef, ###)), NameRef(String, NameRef(Predef, ###))))
42+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
import scala.quoted._
3+
4+
import scala.tasty.typetrees._
5+
6+
import dotty.tools.dotc.quoted.Toolbox._
7+
import dotty.tools.dotc.tasty.Toolbox._
8+
9+
import scala.tasty.typetrees.TypeTree
10+
import scala.tasty.util.TreeTraverser
11+
12+
object Test {
13+
def main(args: Array[String]): Unit = {
14+
val q = '{
15+
val x = 1
16+
val y: x.type = x
17+
def f1[T](): T = ???
18+
def f2[T >: Int <: Int](): T = ???
19+
class Foo { type X }
20+
val foo = new Foo { type X = String }
21+
}
22+
23+
val traverser = new TreeTraverser {
24+
override def traverse(arg: TypeTree): Unit = {
25+
println(arg.tpe)
26+
println()
27+
super.traverse(arg)
28+
}
29+
}
30+
31+
traverser.traverse(toTasty(q))
32+
33+
}
34+
35+
36+
37+
}

0 commit comments

Comments
 (0)