forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi15503i.scala
315 lines (257 loc) · 6.88 KB
/
i15503i.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//> using options -Wunused:all
import collection.mutable.{Map => MutMap} // warn
import collection.mutable.Set // warn
class A {
import collection.mutable.{Map => MutMap} // OK
private val a = 1 // warn
val b = 2 // OK
/* This goes around the trivial method detection */
val default_int = 12
val someMap = MutMap()
private def c1 = 2 // warn
private def c2 = 2 // OK
def c3 = c2
def d1(using x:Int): Int = default_int // ok
def d2(using x:Int): Int = x // OK
def e1(x: Int) = default_int // ok
def e2(x: Int) = x // OK
def f =
val x = 1 // warn
def f = 2 // warn
val y = 3 // OK
def g = 4 // OK
y + g
// todo : uncomment once patvars is fixed
// def g(x: Int): Int = x match
// case x:1 => 0 // ?error
// case x:2 => x // ?OK
// case _ => 1 // ?OK
}
/* ---- CHECK scala.annotation.unused ---- */
package foo.test.scala.annotation:
import annotation.unused // OK
/* This goes around the trivial method detection */
val default_int = 12
def a1(a: Int) = a // OK
def a2(a: Int) = default_int // ok
def a3(@unused a: Int) = default_int //OK
def b1 =
def f = 1 // warn
1
def b2 =
def f = 1 // OK
f
def b3 =
@unused def f = 1 // OK
1
object Foo:
private def a = 1 // warn
private def b = 2 // OK
@unused private def c = 3 // OK
def other = b
package foo.test.companionprivate:
class A:
import A.b // OK
def a = b // OK
object A:
private def b = c // OK
def c = List(1,2,3) // OK
package foo.test.i16678:
def foo(func: Int => String, value: Int): String = func(value) // OK
def run =
println(foo(number => number.toString, value = 5)) // OK
println(foo(number => "<number>", value = 5)) // warn
println(foo(func = number => "<number>", value = 5)) // warn
println(foo(func = number => number.toString, value = 5)) // OK
println(foo(func = _.toString, value = 5)) // OK
package foo.test.possibleclasses:
case class AllCaseClass(
k: Int, // OK
private val y: Int // OK /* Kept as it can be taken from pattern */
)(
s: Int,
val t: Int, // OK
private val z: Int // warn
)
case class AllCaseUsed(
k: Int, // OK
private val y: Int // OK
)(
s: Int, // OK
val t: Int, // OK
private val z: Int // OK
) {
def a = k + y + s + t + z
}
class AllClass(
k: Int, // warn
private val y: Int // warn
)(
s: Int, // warn
val t: Int, // OK
private val z: Int // warn
)
class AllUsed(
k: Int, // OK
private val y: Int // OK
)(
s: Int, // OK
val t: Int, // OK
private val z: Int // OK
) {
def a = k + y + s + t + z
}
package foo.test.possibleclasses.withvar:
case class AllCaseClass(
k: Int, // OK
private var y: Int // OK /* Kept as it can be taken from pattern */
)(
s: Int,
var t: Int, // OK
private var z: Int // warn
)
case class AllCaseUsed(
k: Int, // OK
private var y: Int // OK
)(
s: Int, // OK
var t: Int, // OK global scope can be set somewhere else
private var z: Int // warn not set
) {
def a = k + y + s + t + z
}
class AllClass(
k: Int, // warn
private var y: Int // warn
)(
s: Int, // warn
var t: Int, // OK
private var z: Int // warn
)
class AllUsed(
k: Int, // OK
private var y: Int // warn not set
)(
s: Int, // OK
var t: Int, // OK global scope can be set somewhere else
private var z: Int // warn not set
) {
def a = k + y + s + t + z
}
package foo.test.from.i16675:
case class PositiveNumber private (i: Int) // OK
object PositiveNumber:
def make(i: Int): Option[PositiveNumber] = //OK
Option.when(i >= 0)(PositiveNumber(i)) // OK
package foo.test.i16822:
enum ExampleEnum {
case Build(context: String) // OK
case List // OK
}
def demo = {
val x = ExampleEnum.List // OK
println(x) // OK
}
package foo.test.i16877:
import scala.collection.immutable.HashMap // OK
import scala.annotation.StaticAnnotation // OK
class ExampleAnnotation(val a: Object) extends StaticAnnotation // OK
@ExampleAnnotation(new HashMap()) // OK
class Test //OK
package foo.test.i16926:
def hello(): Unit =
for {
i <- (0 to 10).toList
(a, b) = "hello" -> "world" // OK
} yield println(s"$a $b")
package foo.test.i16925:
def hello =
for {
i <- 1 to 2 if true
_ = println(i) // OK
} yield ()
package foo.test.i16863a:
import scala.quoted.*
def fn(using Quotes) =
val x = Expr(1)
'{ $x + 2 } // OK
package foo.test.i16863b:
import scala.quoted.*
def fn[A](using Quotes, Type[A]) = // OK
val numeric = Expr.summon[Numeric[A]].getOrElse(???)
'{ $numeric.fromInt(3) } // OK
package foo.test.i16863c:
import scala.quoted.*
def fn[A](expr: Expr[Any])(using Quotes) =
val imp = expr match
case '{ ${ _ }: a } => Expr.summon[Numeric[a]] // OK
println(imp)
package foo.test.i16863d:
import scala.quoted.*
import scala.compiletime.asMatchable // OK
def fn[A](using Quotes, Type[A]) =
import quotes.reflect.*
val imp = TypeRepr.of[A].widen.asMatchable match
case Refinement(_,_,_) => ()
println(imp)
package foo.test.i16679a:
object myPackage:
trait CaseClassName[A]:
def name: String
object CaseClassName:
trait CaseClassByStringName[A] extends CaseClassName[A]
import scala.deriving.Mirror
object CaseClassByStringName:
inline final def derived[A](using inline A: Mirror.Of[A]): CaseClassByStringName[A] =
new CaseClassByStringName[A]: // warn
def name: String = A.toString
object secondPackage:
import myPackage.CaseClassName // OK
case class CoolClass(i: Int) derives CaseClassName.CaseClassByStringName
println(summon[CaseClassName[CoolClass]].name)
package foo.test.i16679b:
object myPackage:
trait CaseClassName[A]:
def name: String
object CaseClassName:
import scala.deriving.Mirror
inline final def derived[A](using inline A: Mirror.Of[A]): CaseClassName[A] =
new CaseClassName[A]: // warn
def name: String = A.toString
object Foo:
given x: myPackage.CaseClassName[secondPackage.CoolClass] = null
object secondPackage:
import myPackage.CaseClassName // warn
import Foo.x
case class CoolClass(i: Int)
println(summon[myPackage.CaseClassName[CoolClass]])
package foo.test.i17156:
package a:
trait Foo[A]
object Foo:
inline def derived[T]: Foo[T] = new Foo{} // warn
package b:
import a.Foo
type Xd[A] = Foo[A]
package c:
import b.Xd
trait Z derives Xd
package foo.test.i17175:
val continue = true
def foo =
for {
i <- 1.until(10) // OK
if continue
} {
println(i)
}
package foo.test.i17117:
package example {
object test1 {
val test = "test"
}
object test2 {
import example.test1 as t1
val test = t1.test
}
}