You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/contributing/workflow.md
+29-11Lines changed: 29 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -37,25 +37,43 @@ Here are some useful debugging `<OPTIONS>`:
37
37
can be enabled through the `dotty.tools.dotc.config.Printers` object. Change any of the desired printer from `noPrinter` to
38
38
`default` and this will give you the full logging capability of the compiler.
39
39
40
-
## Inspecting Trees with Type Stealer ##
40
+
## Inspecting Types with Type Stealer ##
41
41
42
-
You can inspect types with the type stealer, open `compiler/test/dotty/tools/DottyTypeStealer.scala` and you'll see:
42
+
You can inspect types with the main method `dotty.tools.printTypes` from the sbt shell,
43
+
passing at least two arguments. The first argument is a string that introduces some
44
+
Scala definitions, the following arguments are type signatures, (i.e. the return type
45
+
of a definition) that are allowed to reference definitions from the first argument.
43
46
44
-
```scala
45
-
@main defsteal() = {
46
-
vals=DottyTypeStealer.stealType("class O { type X }", "O#X")
47
-
valt= s._2(0)
48
-
println(t)
49
-
}
47
+
The type signatures will then be printed, displaying their internal structure, using
48
+
the same representation that can later be used in pattern matching to decompose the type.
49
+
50
+
Here, we inspect a refinement of a class `Box`:
51
+
```bash
52
+
$ sbt
53
+
> scala3-compiler-bootstrapped/Test/runMain dotty.tools.printTypes "class Box { def x: Any }""Box { def x: Int }"
54
+
RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Box),x,ExprType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)))
50
55
```
51
56
57
+
You can also pass the empty string as the first
58
+
argument, e.g. to inspect a standard library type:
AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class *:),List(ConstantType(Constant(1)), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),object Tuple$package),type EmptyTuple)))
56
63
```
57
64
58
-
You can inspect other value types by editing the arguments of `stealType`.
65
+
If you want to further inspect the types, and not just print them, the object `dotty.tools.DottyTypeStealer` has a
66
+
method `stealType`. It takes the same arguments as `printTypes`, but returns both a `Context` containing the
0 commit comments