Skip to content

Commit 000a541

Browse files
authored
Merge pull request #12833 from tanishiking/update-doc-dotty-type-stealer
Update document for DottyTypeStealer
2 parents b5def4d + 329e2ac commit 000a541

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
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`,

docs/docs/internals/type-system.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,24 @@ Type -+- ProxyType --+- NamedType ----+--- TypeRef
2323
| | +--- ThisType
2424
| | +--- SuperType
2525
| | +--- ConstantType
26-
| | +--- MethodParam
26+
| | +--- TermParamRef
2727
| | +----RecThis
2828
| | +--- SkolemType
29-
| +- PolyParam
29+
| +- TypeParamRef
3030
| +- RefinedOrRecType -+-- RefinedType
3131
| | -+-- RecType
32-
| +- HKApply
32+
| +- AppliedType
3333
| +- TypeBounds
3434
| +- ExprType
3535
| +- AnnotatedType
3636
| +- TypeVar
37-
| +- PolyType
37+
| +- HKTypeLambda
38+
| +- MatchType
3839
|
3940
+- GroundType -+- AndType
4041
+- OrType
41-
+- MethodType -----+- ImplicitMethodType
42-
| +- JavaMethodType
42+
+- MethodOrPoly ---+-- PolyType
43+
| +-- MethodType
4344
+- ClassInfo
4445
|
4546
+- NoType

0 commit comments

Comments
 (0)