Skip to content

Commit 8336de6

Browse files
committed
Update document for DottyTypeStealer
1 parent 076ab0a commit 8336de6

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

compiler/test/dotty/tools/DottyTypeStealer.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import dotc.core.Contexts.Context
77
import dotc.core.Decorators._
88
import dotc.core.Types.Type
99

10+
@main def steal() = {
11+
val s = DottyTypeStealer.stealType("class O { type X }", "O#X")
12+
val t = s._2(0)
13+
println(t)
14+
}
15+
1016
object DottyTypeStealer extends DottyTest {
1117
def stealType(source: String, typeStrings: String*): (Context, List[Type]) = {
1218
val dummyName = "x_x_x"

docs/docs/contributing/workflow.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,23 @@ can be enabled through the `dotty.tools.dotc.config.Printers` object. Change any
3939

4040
## Inspecting Trees with Type Stealer ##
4141

42-
There is no power mode for the REPL yet, but you can inspect types with the
43-
type stealer:
42+
You can inspect types with the type stealer, open `compiler/test/dotty/tools/DottyTypeStealer.scala` and you'll see:
43+
44+
```scala
45+
@main def steal() = {
46+
val s = DottyTypeStealer.stealType("class O { type X }", "O#X")
47+
val t = s._2(0)
48+
println(t)
49+
}
50+
```
4451

4552
```bash
4653
$ sbt
47-
> repl
48-
scala> import dotty.tools.DottyTypeStealer.*; import dotty.tools.dotc.core.*; import Contexts.*,Types.*
54+
> scala3-compiler-bootstrapped/Test/runMain dotty.tools.steal
55+
TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class O),type X)
4956
```
5057

51-
Now, you can define types and access their representation. For example:
52-
53-
```scala
54-
scala> val s = stealType("class O { type X }", "O#X")
55-
scala> implicit val ctx: Context = s._1
56-
scala> val t = s._2(0)
57-
t: dotty.tools.dotc.core.Types.Type = TypeRef(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),O),X)
58-
scala> val u = t.asInstanceOf[TypeRef].underlying
59-
u: dotty.tools.dotc.core.Types.Type = TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing), TypeRef(ThisType(TypeRef(NoPrefix,scala)),Any))
60-
```
58+
You can inspect other value types by editing the arguments of `stealType`.
6159

6260
## Pretty-printing ##
6361
Many objects in the scalac compiler implement a `Showable` trait (e.g. `Tree`,

0 commit comments

Comments
 (0)