@@ -144,3 +144,55 @@ object Test {
144
144
}
145
145
}
146
146
```
147
+
148
+
149
+ Rules
150
+ -----
151
+
152
+ 1 ) The ` unused ` modifier can appear:
153
+ * At the start of a parameter block of a method, function or class
154
+ * In a method definition
155
+ * In a ` val ` definition (but not ` lazy val ` or ` var ` )
156
+
157
+ ``` scala
158
+ unused val x = ...
159
+ unused def f = ...
160
+
161
+ def g (unused x : Int ) = ...
162
+
163
+ (unused x : Int ) => ...
164
+ def h (x : unused Int => Int ) = ...
165
+
166
+ class K (unused x : Int ) { ... }
167
+ ```
168
+
169
+ 2 ) A reference to an ` unused ` definition can only be used
170
+ * Inside the expression of argument to an ` unused ` parameter
171
+ * Inside the body of an ` unused ` ` val ` or ` def `
172
+
173
+ 3 ) Functions
174
+ * ` (unused x1: T1, x2: T2, ..., xN: TN) => y : (unused T1, T2, ..., TN) => R `
175
+ * ` (implicit unused x1: T1, x2: T2, ..., xN: TN) => y : (implicit unused T1, T2, ..., TN) => R `
176
+ * ` implicit unused T1 => R <:< unused T1 => R `
177
+ * ` (implicit unused T1, T2) => R <:< (unused T1, T2) => R `
178
+ * ...
179
+
180
+ Note that there is no subtype relation between ` unused T => R ` and ` T => R ` (or ` implicit unused T => R ` and ` implicit T => R ` )
181
+
182
+ 4 ) Eta expansion
183
+ if ` def f(unused x: T): U ` then ` f: (unused T) => U ` .
184
+
185
+
186
+ 5 ) Erasure Semantics
187
+ * All ` unused ` paramters are removed from the function
188
+ * All argument to ` unused ` paramters are not passed to the function
189
+ * All ` unused ` definitions are removed
190
+ * All ` (unused T1, T2, ..., TN) => R ` and ` (implicit unused T1, T2, ..., TN) => R ` become ` () => R `
191
+
192
+ 6 ) Overloading
193
+ Method with ` unused ` parameters will follow the normal overloading constraints after erasure.
194
+
195
+ 7 ) Overriding
196
+ * Member definitions overidding each other must both be ` unused ` or not be ` unused `
197
+ * ` def foo(x: T): U ` cannot be overriden by ` def foo(unused x: T): U ` an viceversa
198
+
0 commit comments