-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move warn tests form tests/error to tests/warn
- Loading branch information
Showing
99 changed files
with
3,233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//> using options -deprecation | ||
|
||
def usered = Color.Red // warn: value Red is deprecated | ||
|
||
object DeprecatedContainer { | ||
@deprecated("no foo", "0.1") val foo = 23 | ||
} | ||
|
||
enum Day { | ||
|
||
@deprecated("no more Mondays!", "0.1") case Monday | ||
|
||
} | ||
|
||
enum Color { | ||
|
||
@deprecated("no Red", "0.1") case Red | ||
|
||
@deprecated("no Generic", "0.1") case Generic(rgb: Int) | ||
|
||
def useFoo1 = DeprecatedContainer.foo // warn // check that only enum cases are avoided | ||
def useMonday = Day.Monday // warn // check that enum cases are declared in this enum | ||
|
||
} | ||
|
||
object Color { | ||
def useFoo2 = DeprecatedContainer.foo // warn // check that only enum cases are avoided | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
import language.future | ||
@main def Test = | ||
type LeafElem[X] = X match | ||
case String => Char | ||
case Array[t] => LeafElem[t] | ||
case Iterable[t] => LeafElem[t] | ||
case AnyVal => X | ||
|
||
def leafElem[X](x: X): LeafElem[X] = x match | ||
case x: String => x.charAt(0) // warn | ||
case x: Array[t] => leafElem(x(1)) // warn | ||
case x: Iterable[t] => leafElem(x.head) // warn | ||
case x: AnyVal => x // warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
def foo = true match | ||
case (b: Boolean): Boolean => () // warn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- Deprecation Warning: tests/warn/i11022.scala:10:7 ------------------------------------------------------------------- | ||
10 |val a: CaseClass = CaseClass(42) // warn: deprecated type // warn: deprecated apply method | ||
| ^^^^^^^^^ | ||
| class CaseClass is deprecated: no CaseClass | ||
-- Deprecation Warning: tests/warn/i11022.scala:10:19 ------------------------------------------------------------------ | ||
10 |val a: CaseClass = CaseClass(42) // warn: deprecated type // warn: deprecated apply method | ||
| ^^^^^^^^^ | ||
| class CaseClass is deprecated: no CaseClass | ||
-- Deprecation Warning: tests/warn/i11022.scala:11:7 ------------------------------------------------------------------- | ||
11 |val b: CaseClass = new CaseClass(42) // warn: deprecated type // warn: deprecated class | ||
| ^^^^^^^^^ | ||
| class CaseClass is deprecated: no CaseClass | ||
-- Deprecation Warning: tests/warn/i11022.scala:11:23 ------------------------------------------------------------------ | ||
11 |val b: CaseClass = new CaseClass(42) // warn: deprecated type // warn: deprecated class | ||
| ^^^^^^^^^ | ||
| class CaseClass is deprecated: no CaseClass | ||
-- Deprecation Warning: tests/warn/i11022.scala:12:14 ------------------------------------------------------------------ | ||
12 |val c: Unit = CaseClass(42).magic() // warn: deprecated apply method | ||
| ^^^^^^^^^ | ||
| class CaseClass is deprecated: no CaseClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//> using options -deprecation | ||
|
||
@deprecated("no CaseClass") | ||
case class CaseClass(rgb: Int): | ||
def magic(): Unit = () | ||
|
||
object CaseClass: | ||
def notDeprecated(): Unit = () | ||
|
||
val a: CaseClass = CaseClass(42) // warn: deprecated type // warn: deprecated apply method | ||
val b: CaseClass = new CaseClass(42) // warn: deprecated type // warn: deprecated class | ||
val c: Unit = CaseClass(42).magic() // warn: deprecated apply method | ||
val d: Unit = CaseClass.notDeprecated() // compiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
@main def test: Unit = { | ||
class C { type T1; type T2 } | ||
|
||
def pmatch(s: C): s.T2 = s match { | ||
case p: (C { type T1 = Int; type T2 >: T1 } & s.type) => // warn | ||
(3: p.T1): p.T2 | ||
case p: (C { type T1 = String; type T2 >: T1 } & s.type) => // warn | ||
("this branch should be matched": p.T1): p.T2 | ||
} | ||
|
||
// ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String | ||
val x = pmatch(new C { type T1 = String; type T2 = String }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:4:19 ------------------------------------------------------- | ||
4 | val f1: Float = 123456789 // warn | ||
| ^^^^^^^^^ | ||
| Widening conversion from Int to Float loses precision. | ||
| Write `.toFloat` instead. | ||
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:5:19 ------------------------------------------------------- | ||
5 | val d1: Double = 1234567890123456789L // warn | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| Widening conversion from Long to Double loses precision. | ||
| Write `.toDouble` instead. | ||
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:6:19 ------------------------------------------------------- | ||
6 | val f2: Float = 123456789L // warn | ||
| ^^^^^^^^^^ | ||
| Widening conversion from Long to Float loses precision. | ||
| Write `.toFloat` instead. | ||
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:12:21 ------------------------------------------------------ | ||
12 | val f1_b: Float = i1 // warn | ||
| ^^ | ||
| Widening conversion from Int to Float loses precision. | ||
| Write `.toFloat` instead. | ||
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:13:21 ------------------------------------------------------ | ||
13 | val d1_b: Double = l1 // warn | ||
| ^^ | ||
| Widening conversion from Long to Double loses precision. | ||
| Write `.toDouble` instead. | ||
-- [E167] Lossy Conversion Warning: tests/warn/i11333.scala:14:21 ------------------------------------------------------ | ||
14 | val f2_b: Float = l2 // warn | ||
| ^^ | ||
| Widening conversion from Long to Float loses precision. | ||
| Write `.toFloat` instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
|
||
class C: | ||
val f1: Float = 123456789 // warn | ||
val d1: Double = 1234567890123456789L // warn | ||
val f2: Float = 123456789L // warn | ||
|
||
inline val i1 = 123456789 | ||
inline val l1 = 1234567890123456789L | ||
inline val l2 = 123456789L | ||
|
||
val f1_b: Float = i1 // warn | ||
val d1_b: Double = l1 // warn | ||
val f2_b: Float = l2 // warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//> using options -deprecation | ||
|
||
trait Pet(val name: String, rest: Int): | ||
def f(suffix: String) = s"$name$suffix$rest" | ||
|
||
class Birdie(override val name: String) extends Pet("huh", 1) // warn | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
open trait Foo // warn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
open abstract class Foo // warn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
object Test { | ||
def foo: Any = { | ||
open class Bar // warn | ||
new Bar | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- [E092] Pattern Match Unchecked Warning: tests/warn/i12253.scala:13:10 ----------------------------------------------- | ||
13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // warn // warn | ||
| ^ | ||
|the type test for extractors.q2.reflect.Term cannot be checked at runtime because it refers to an abstract type member or type parameter | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E092] Pattern Match Unchecked Warning: tests/warn/i12253.scala:13:38 ----------------------------------------------- | ||
13 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // warn // warn | ||
| ^ | ||
|the type test for q1.reflect.Select cannot be checked at runtime because it refers to an abstract type member or type parameter | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
there was 1 deprecation warning; re-run with -deprecation for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
|
||
import scala.quoted.{given, *} | ||
import deriving.*, compiletime.* | ||
|
||
object MacroUtils: | ||
transparent inline def extractNameFromSelector[To, T](inline code: To => T) = ${extractNameFromSelectorImpl('code)} | ||
|
||
def extractNameFromSelectorImpl[To: Type, T: Type](code: Expr[To => T])(using q1: Quotes): Expr[String] = | ||
import quotes.reflect.* | ||
val extractors = new Extractors | ||
code.asTerm match | ||
case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // warn // warn | ||
case t => report.throwError(s"Illegal argument to extractor: ${code.show}, in tasty: $t") | ||
|
||
class Extractors(using val q2: Quotes): | ||
//attempt to strip away consecutive inlines in AST and extract only final lambda | ||
import quotes.reflect.* | ||
|
||
object InlinedLambda: | ||
def unapply(arg: Term): Option[(List[ValDef], Term)] = | ||
arg match | ||
case Inlined(_, _, Lambda(vals, term)) => Some((vals, term)) | ||
case Inlined(_, _, nested) => InlinedLambda.unapply(nested) | ||
case t => None | ||
end InlinedLambda | ||
|
||
end Extractors | ||
end MacroUtils | ||
|
||
// nopos-warn deprecation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//> using options -deprecation | ||
|
||
@main def Test = | ||
val a: IArray[Int] = IArray(2) | ||
val b: IArray[Any] = a | ||
val c = b.toArray // warn: deprecated | ||
c(0) = "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
class i13011 { | ||
lazy implicit val simple1: String = simple1 // warn | ||
def f: Unit = { | ||
lazy val simple2: String = simple2 // warn | ||
} | ||
|
||
lazy val simple3: String = if true then this.simple3 else "a" // warn | ||
|
||
def firstDigitIsEven(n: Int): Boolean = if n % 10 == n then n % 2 == 0 else firstDigitIsEven(n / 10) | ||
|
||
lazy val simple4: String = if firstDigitIsEven(22) then this.simple4 else "a" // ok | ||
|
||
lazy val simple5: String = identity(this.simple5) // warn | ||
|
||
lazy val simple6: String = { // warn | ||
this.simple6 | ||
"aa" | ||
} | ||
|
||
lazy val simple7: Function0[Any] = () => this.simple7 // Ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- Migration Warning: tests/warn/i13440.scala:5:4 ---------------------------------------------------------------------- | ||
5 |def given = 42 // warn | ||
| ^ | ||
| given is now a keyword, write `given` instead of given to keep it as an identifier | ||
-- Migration Warning: tests/warn/i13440.scala:7:13 --------------------------------------------------------------------- | ||
7 |case class C(enum: List[Int] = Nil) { // warn | ||
| ^ | ||
| enum is now a keyword, write `enum` instead of enum to keep it as an identifier | ||
-- Migration Warning: tests/warn/i13440.scala:8:11 --------------------------------------------------------------------- | ||
8 | val s = s"$enum" // warn | ||
| ^ | ||
| enum is now a keyword, write `enum` instead of enum to keep it as an identifier | ||
| This can be rewritten automatically under -rewrite -source 3.0-migration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
import language.`3.0-migration` | ||
|
||
def given = 42 // warn | ||
|
||
case class C(enum: List[Int] = Nil) { // warn | ||
val s = s"$enum" // warn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
|
||
import scala.language.implicitConversions | ||
|
||
case class Foo(i: Int) extends AnyVal: | ||
def toFoo = this | ||
|
||
case class Bar(i: Int) extends AnyVal | ||
|
||
class BarOps(bar: Bar): | ||
def toFoo = Foo(bar.i) | ||
|
||
implicit def augmentBar(bar: Bar): BarOps = BarOps(bar) | ||
|
||
def lazyIdentity[T](x: => T): T = x | ||
def repIdentity[T](x: T*): T = x(0) | ||
|
||
val x1 = | ||
implicit def barToFoo(bar: Bar): Foo = bar.toFoo // warn: infinite loop in function body | ||
val foo: Foo = Bar(1) | ||
|
||
val x2 = | ||
implicit def barToFoo2(bar: Bar): Foo = | ||
identity(bar.toFoo) // warn | ||
val foo: Foo = Bar(1) | ||
|
||
val x3 = | ||
implicit def barToFoo3(bar: Bar): Foo = | ||
lazyIdentity(bar.toFoo) // OK | ||
val foo: Foo = Bar(1) | ||
|
||
val x4 = | ||
implicit def barToFoo4(bar: Bar): Foo = | ||
repIdentity(bar.toFoo) // warn | ||
val foo: Foo = Bar(1) | ||
|
||
val x5 = | ||
implicit def barToFoo4(bar: Bar): Foo = | ||
val y = bar.toFoo // warn | ||
y | ||
val foo: Foo = Bar(1) | ||
|
||
val x6 = | ||
implicit def barToFoo4(bar: Bar): Foo = | ||
lazy val y = bar.toFoo | ||
if false then y else ??? | ||
val foo: Foo = Bar(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
|
||
val n = Nil | ||
val b = n.head.isInstanceOf[String] // warn | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
class C: | ||
def op: Unit = println("op") | ||
def handler: Unit = println("handler") | ||
def test: Unit = | ||
try op | ||
catch case _: NullPointerException => | ||
handler // warn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
|
||
import scala.language.implicitConversions | ||
|
||
object Test1: | ||
given c: Conversion[ String, Int ] with | ||
def apply(from: String): Int = from.toInt // warn | ||
|
||
object Test2: | ||
given c: Conversion[ String, Int ] = _.toInt // loop not detected, could be used as a fallback to avoid the warning. | ||
|
||
object Prices { | ||
opaque type Price = BigDecimal | ||
|
||
object Price{ | ||
given Ordering[Price] = summon[Ordering[BigDecimal]] // warn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//> using options -source future -deprecation | ||
|
||
package deptest { | ||
@deprecated("Not used any more", since="7") | ||
object DeprecatedThing { | ||
val oldValue = 42 | ||
} | ||
} | ||
|
||
package depuser { | ||
import deptest.DeprecatedThing.* // warn | ||
|
||
object DepUser { | ||
def main(args: Array[String]): Unit = println { | ||
oldValue | ||
} | ||
} | ||
} |
Oops, something went wrong.