@@ -66,7 +66,6 @@ unused val unusedEvidence: Ev = ...
66
66
methodWithUnusedEv(unusedEvidence)
67
67
```
68
68
69
-
70
69
What happens with unused values at runtime?
71
70
-------------------------------------------
72
71
As ` unused ` are guaranteed not to be used in computations, they can and will be erased.
@@ -79,11 +78,8 @@ def evidence1: Ev = ...
79
78
unused def unusedEvidence2 : Ev = ... // does not exist at runtime
80
79
unused val unusedEvidence3 : Ev = ... // does not exist at runtime
81
80
82
- // evidence1 is evaluated but the result is not passed to methodWithUnusedEv
81
+ // evidence1 is not evaluated and no value is passed to methodWithUnusedEv
83
82
methodWithUnusedEv(evidence1)
84
-
85
- // unusedEvidence2 is not evaluated and its result is not passed to methodWithUnusedEv
86
- methodWithUnusedEv(unusedEvidence2)
87
83
```
88
84
89
85
State machine with unused evidence example
@@ -111,14 +107,14 @@ final class Off extends State
111
107
@ implicitNotFound(" State is must be Off" )
112
108
class IsOff [S <: State ]
113
109
object IsOff {
114
- // def isOff will not exist at runtime
115
- unused implicit def isOff : IsOff [Off ] = new IsOff [Off ]
110
+ // def isOff will not be called at runtime for turnedOn, the compiler will only require that this evidence exists
111
+ implicit def isOff : IsOff [Off ] = new IsOff [Off ]
116
112
}
117
113
118
114
@ implicitNotFound(" State is must be On" )
119
115
class IsOn [S <: State ]
120
116
object IsOn {
121
- // val isOn will not exist at runtime
117
+ // def isOn will not exist at runtime, the compiler will only require that this evidence exists at compile time
122
118
unused implicit val isOn : IsOn [On ] = new IsOn [On ]
123
119
}
124
120
0 commit comments