Skip to content

Commit 9858d79

Browse files
committed
Move warn tests form tests/error to tests/warn
1 parent 85c0630 commit 9858d79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+3233
-0
lines changed

tests/warn/i10247.scala

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//> using options -deprecation
2+
3+
def usered = Color.Red // warn: value Red is deprecated
4+
5+
object DeprecatedContainer {
6+
@deprecated("no foo", "0.1") val foo = 23
7+
}
8+
9+
enum Day {
10+
11+
@deprecated("no more Mondays!", "0.1") case Monday
12+
13+
}
14+
15+
enum Color {
16+
17+
@deprecated("no Red", "0.1") case Red
18+
19+
@deprecated("no Generic", "0.1") case Generic(rgb: Int)
20+
21+
def useFoo1 = DeprecatedContainer.foo // warn // check that only enum cases are avoided
22+
def useMonday = Day.Monday // warn // check that enum cases are declared in this enum
23+
24+
}
25+
26+
object Color {
27+
def useFoo2 = DeprecatedContainer.foo // warn // check that only enum cases are avoided
28+
}

tests/warn/i10930.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
import language.future
4+
@main def Test =
5+
type LeafElem[X] = X match
6+
case String => Char
7+
case Array[t] => LeafElem[t]
8+
case Iterable[t] => LeafElem[t]
9+
case AnyVal => X
10+
11+
def leafElem[X](x: X): LeafElem[X] = x match
12+
case x: String => x.charAt(0) // warn
13+
case x: Array[t] => leafElem(x(1)) // warn
14+
case x: Iterable[t] => leafElem(x.head) // warn
15+
case x: AnyVal => x // warn

tests/warn/i10994.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
def foo = true match
4+
case (b: Boolean): Boolean => () // warn
5+

tests/warn/i11022.check

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Deprecation Warning: tests/warn/i11022.scala:10:7 -------------------------------------------------------------------
2+
10 |val a: CaseClass = CaseClass(42) // warn: deprecated type // warn: deprecated apply method
3+
| ^^^^^^^^^
4+
| class CaseClass is deprecated: no CaseClass
5+
-- Deprecation Warning: tests/warn/i11022.scala:10:19 ------------------------------------------------------------------
6+
10 |val a: CaseClass = CaseClass(42) // warn: deprecated type // warn: deprecated apply method
7+
| ^^^^^^^^^
8+
| class CaseClass is deprecated: no CaseClass
9+
-- Deprecation Warning: tests/warn/i11022.scala:11:7 -------------------------------------------------------------------
10+
11 |val b: CaseClass = new CaseClass(42) // warn: deprecated type // warn: deprecated class
11+
| ^^^^^^^^^
12+
| class CaseClass is deprecated: no CaseClass
13+
-- Deprecation Warning: tests/warn/i11022.scala:11:23 ------------------------------------------------------------------
14+
11 |val b: CaseClass = new CaseClass(42) // warn: deprecated type // warn: deprecated class
15+
| ^^^^^^^^^
16+
| class CaseClass is deprecated: no CaseClass
17+
-- Deprecation Warning: tests/warn/i11022.scala:12:14 ------------------------------------------------------------------
18+
12 |val c: Unit = CaseClass(42).magic() // warn: deprecated apply method
19+
| ^^^^^^^^^
20+
| class CaseClass is deprecated: no CaseClass

tests/warn/i11022.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -deprecation
2+
3+
@deprecated("no CaseClass")
4+
case class CaseClass(rgb: Int):
5+
def magic(): Unit = ()
6+
7+
object CaseClass:
8+
def notDeprecated(): Unit = ()
9+
10+
val a: CaseClass = CaseClass(42) // warn: deprecated type // warn: deprecated apply method
11+
val b: CaseClass = new CaseClass(42) // warn: deprecated type // warn: deprecated class
12+
val c: Unit = CaseClass(42).magic() // warn: deprecated apply method
13+
val d: Unit = CaseClass.notDeprecated() // compiles

tests/warn/i11097.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
@main def test: Unit = {
4+
class C { type T1; type T2 }
5+
6+
def pmatch(s: C): s.T2 = s match {
7+
case p: (C { type T1 = Int; type T2 >: T1 } & s.type) => // warn
8+
(3: p.T1): p.T2
9+
case p: (C { type T1 = String; type T2 >: T1 } & s.type) => // warn
10+
("this branch should be matched": p.T1): p.T2
11+
}
12+
13+
// ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String
14+
val x = pmatch(new C { type T1 = String; type T2 = String })
15+
}

tests/warn/i11333.check

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:4:19 -------------------------------------------------------
2+
4 | val f1: Float = 123456789 // warn
3+
| ^^^^^^^^^
4+
| Widening conversion from Int to Float loses precision.
5+
| Write `.toFloat` instead.
6+
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:5:19 -------------------------------------------------------
7+
5 | val d1: Double = 1234567890123456789L // warn
8+
| ^^^^^^^^^^^^^^^^^^^^
9+
| Widening conversion from Long to Double loses precision.
10+
| Write `.toDouble` instead.
11+
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:6:19 -------------------------------------------------------
12+
6 | val f2: Float = 123456789L // warn
13+
| ^^^^^^^^^^
14+
| Widening conversion from Long to Float loses precision.
15+
| Write `.toFloat` instead.
16+
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:12:21 ------------------------------------------------------
17+
12 | val f1_b: Float = i1 // warn
18+
| ^^
19+
| Widening conversion from Int to Float loses precision.
20+
| Write `.toFloat` instead.
21+
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:13:21 ------------------------------------------------------
22+
13 | val d1_b: Double = l1 // warn
23+
| ^^
24+
| Widening conversion from Long to Double loses precision.
25+
| Write `.toDouble` instead.
26+
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:14:21 ------------------------------------------------------
27+
14 | val f2_b: Float = l2 // warn
28+
| ^^
29+
| Widening conversion from Long to Float loses precision.
30+
| Write `.toFloat` instead.

tests/warn/i11333.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
class C:
4+
val f1: Float = 123456789 // warn
5+
val d1: Double = 1234567890123456789L // warn
6+
val f2: Float = 123456789L // warn
7+
8+
inline val i1 = 123456789
9+
inline val l1 = 1234567890123456789L
10+
inline val l2 = 123456789L
11+
12+
val f1_b: Float = i1 // warn
13+
val d1_b: Double = l1 // warn
14+
val f2_b: Float = l2 // warn

tests/warn/i11344.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -deprecation
2+
3+
trait Pet(val name: String, rest: Int):
4+
def f(suffix: String) = s"$name$suffix$rest"
5+
6+
class Birdie(override val name: String) extends Pet("huh", 1) // warn
7+
8+
9+

tests/warn/i11963a.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
open trait Foo // warn
4+

tests/warn/i11963b.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
open abstract class Foo // warn
4+

tests/warn/i11963c.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
object Test {
4+
def foo: Any = {
5+
open class Bar // warn
6+
new Bar
7+
}
8+
}

tests/warn/i12253.check

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- [E092] Pattern Match Unchecked Warning: tests/warn/i12253.scala:13:10 -----------------------------------------------
2+
13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // warn // warn
3+
| ^
4+
|the type test for extractors.q2.reflect.Term cannot be checked at runtime because it refers to an abstract type member or type parameter
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E092] Pattern Match Unchecked Warning: tests/warn/i12253.scala:13:38 -----------------------------------------------
8+
13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // warn // warn
9+
| ^
10+
|the type test for q1.reflect.Select cannot be checked at runtime because it refers to an abstract type member or type parameter
11+
|
12+
| longer explanation available when compiling with `-explain`
13+
there was 1 deprecation warning; re-run with -deprecation for details

tests/warn/i12253.scala

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
3+
import scala.quoted.{given, *}
4+
import deriving.*, compiletime.*
5+
6+
object MacroUtils:
7+
transparent inline def extractNameFromSelector[To, T](inline code: To => T) = ${extractNameFromSelectorImpl('code)}
8+
9+
def extractNameFromSelectorImpl[To: Type, T: Type](code: Expr[To => T])(using q1: Quotes): Expr[String] =
10+
import quotes.reflect.*
11+
val extractors = new Extractors
12+
code.asTerm match
13+
case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // warn // warn
14+
case t => report.throwError(s"Illegal argument to extractor: ${code.show}, in tasty: $t")
15+
16+
class Extractors(using val q2: Quotes):
17+
//attempt to strip away consecutive inlines in AST and extract only final lambda
18+
import quotes.reflect.*
19+
20+
object InlinedLambda:
21+
def unapply(arg: Term): Option[(List[ValDef], Term)] =
22+
arg match
23+
case Inlined(_, _, Lambda(vals, term)) => Some((vals, term))
24+
case Inlined(_, _, nested) => InlinedLambda.unapply(nested)
25+
case t => None
26+
end InlinedLambda
27+
28+
end Extractors
29+
end MacroUtils
30+
31+
// nopos-warn deprecation

tests/warn/i12597.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -deprecation
2+
3+
@main def Test =
4+
val a: IArray[Int] = IArray(2)
5+
val b: IArray[Any] = a
6+
val c = b.toArray // warn: deprecated
7+
c(0) = ""
8+

tests/warn/i13011.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
class i13011 {
4+
lazy implicit val simple1: String = simple1 // warn
5+
def f: Unit = {
6+
lazy val simple2: String = simple2 // warn
7+
}
8+
9+
lazy val simple3: String = if true then this.simple3 else "a" // warn
10+
11+
def firstDigitIsEven(n: Int): Boolean = if n % 10 == n then n % 2 == 0 else firstDigitIsEven(n / 10)
12+
13+
lazy val simple4: String = if firstDigitIsEven(22) then this.simple4 else "a" // ok
14+
15+
lazy val simple5: String = identity(this.simple5) // warn
16+
17+
lazy val simple6: String = { // warn
18+
this.simple6
19+
"aa"
20+
}
21+
22+
lazy val simple7: Function0[Any] = () => this.simple7 // Ok
23+
}

tests/warn/i13440.check

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Migration Warning: tests/warn/i13440.scala:5:4 ----------------------------------------------------------------------
2+
5 |def given = 42 // warn
3+
| ^
4+
| given is now a keyword, write `given` instead of given to keep it as an identifier
5+
-- Migration Warning: tests/warn/i13440.scala:7:13 ---------------------------------------------------------------------
6+
7 |case class C(enum: List[Int] = Nil) { // warn
7+
| ^
8+
| enum is now a keyword, write `enum` instead of enum to keep it as an identifier
9+
-- Migration Warning: tests/warn/i13440.scala:8:11 ---------------------------------------------------------------------
10+
8 | val s = s"$enum" // warn
11+
| ^
12+
| enum is now a keyword, write `enum` instead of enum to keep it as an identifier
13+
| This can be rewritten automatically under -rewrite -source 3.0-migration.

tests/warn/i13440.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
import language.`3.0-migration`
4+
5+
def given = 42 // warn
6+
7+
case class C(enum: List[Int] = Nil) { // warn
8+
val s = s"$enum" // warn
9+
}

tests/warn/i13542.scala

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
3+
import scala.language.implicitConversions
4+
5+
case class Foo(i: Int) extends AnyVal:
6+
def toFoo = this
7+
8+
case class Bar(i: Int) extends AnyVal
9+
10+
class BarOps(bar: Bar):
11+
def toFoo = Foo(bar.i)
12+
13+
implicit def augmentBar(bar: Bar): BarOps = BarOps(bar)
14+
15+
def lazyIdentity[T](x: => T): T = x
16+
def repIdentity[T](x: T*): T = x(0)
17+
18+
val x1 =
19+
implicit def barToFoo(bar: Bar): Foo = bar.toFoo // warn: infinite loop in function body
20+
val foo: Foo = Bar(1)
21+
22+
val x2 =
23+
implicit def barToFoo2(bar: Bar): Foo =
24+
identity(bar.toFoo) // warn
25+
val foo: Foo = Bar(1)
26+
27+
val x3 =
28+
implicit def barToFoo3(bar: Bar): Foo =
29+
lazyIdentity(bar.toFoo) // OK
30+
val foo: Foo = Bar(1)
31+
32+
val x4 =
33+
implicit def barToFoo4(bar: Bar): Foo =
34+
repIdentity(bar.toFoo) // warn
35+
val foo: Foo = Bar(1)
36+
37+
val x5 =
38+
implicit def barToFoo4(bar: Bar): Foo =
39+
val y = bar.toFoo // warn
40+
y
41+
val foo: Foo = Bar(1)
42+
43+
val x6 =
44+
implicit def barToFoo4(bar: Bar): Foo =
45+
lazy val y = bar.toFoo
46+
if false then y else ???
47+
val foo: Foo = Bar(1)

tests/warn/i14705.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
val n = Nil
4+
val b = n.head.isInstanceOf[String] // warn
5+
6+

tests/warn/i14721.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
class C:
4+
def op: Unit = println("op")
5+
def handler: Unit = println("handler")
6+
def test: Unit =
7+
try op
8+
catch case _: NullPointerException =>
9+
handler // warn
10+

tests/warn/i15474.scala

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
import scala.language.implicitConversions
4+
5+
object Test1:
6+
given c: Conversion[ String, Int ] with
7+
def apply(from: String): Int = from.toInt // warn
8+
9+
object Test2:
10+
given c: Conversion[ String, Int ] = _.toInt // loop not detected, could be used as a fallback to avoid the warning.
11+
12+
object Prices {
13+
opaque type Price = BigDecimal
14+
15+
object Price{
16+
given Ordering[Price] = summon[Ordering[BigDecimal]] // warn
17+
}
18+
}

tests/warn/i15479.scala

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//> using options -source future -deprecation
2+
3+
package deptest {
4+
@deprecated("Not used any more", since="7")
5+
object DeprecatedThing {
6+
val oldValue = 42
7+
}
8+
}
9+
10+
package depuser {
11+
import deptest.DeprecatedThing.* // warn
12+
13+
object DepUser {
14+
def main(args: Array[String]): Unit = println {
15+
oldValue
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)