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
+28-11Lines changed: 28 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -40,35 +40,52 @@ can be enabled through the `dotty.tools.dotc.config.Printers` object. Change any
40
40
## Inspecting Types with Type Stealer ##
41
41
42
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.
46
-
47
-
The type signatures will then be printed, displaying their internal structure, using
43
+
passing at least three arguments:
44
+
- The first argument is a string that introduces some
45
+
Scala definitions
46
+
- The second argument introduces how the the remaining arguments should be interpreted,
47
+
comprising of
48
+
-`rhs` - the return type of a definition
49
+
-`class` - the signature of a class, after its name
50
+
-`method` - the signature of a method, after its name
51
+
-`type` - the signature of a type, after its name
52
+
- The remaining arguments are type signatures, these may reference definitions introduced by the first argument.
53
+
54
+
Each type signature is then be printed, displaying their internal structure, alongside their class, using
48
55
the same representation that can later be used in pattern matching to decompose the type.
49
56
50
57
Here, we inspect a refinement of a class `Box`:
51
58
```bash
52
59
$ 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)))
60
+
> scala3-compiler-bootstrapped/Test/runMain dotty.tools.printTypes "class Box { def x: Any }""rhs""Box { def x: Int }"
61
+
RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Box), x, ExprType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int))) [class dotty.tools.dotc.core.Types$CachedRefinedType]
55
62
```
56
63
57
-
You can also pass the empty string as the first
64
+
You can also pass the empty string as the second
58
65
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)))
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)))
63
70
```
64
71
72
+
Here are some other examples you can follow:
73
+
-`...printTypes "" class "[T] extends Foo[T] {}"`
74
+
-`...printTypes "" method "(x: Int): x.type"`
75
+
-`...printTypes "" type "<: Int" "= [T] =>> List[T]"`
76
+
65
77
If you want to further inspect the types, and not just print them, the object `dotty.tools.DottyTypeStealer` has a
66
78
method `stealType`. It takes the same arguments as `printTypes`, but returns both a `Context` containing the
0 commit comments