Skip to content

Commit 3389ab0

Browse files
authored
Merge pull request #1360 from yadavan88/warning-rewrite
Fixed many compiler warnings after Scala 3.4 migration
2 parents 87b70bd + 032dcde commit 3389ab0

File tree

63 files changed

+148
-133
lines changed

Some content is hidden

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

63 files changed

+148
-133
lines changed

play-scala/dependency-injection/app/models/Order.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package models
33
import play.api.libs.json.Json
44

55
object Order {
6-
implicit val writes = Json.writes[Order]
6+
implicit val writes: play.api.libs.json.OWrites[models.Order] =
7+
Json.writes[Order]
78
}
89

910
case class Order(id: Long, userId: Long, date: Long, isEnterprise: Boolean)

play-scala/dependency-injection/app/models/User.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import play.api.libs.json.Json
55
case class User(id: Long, name: String)
66

77
object User {
8-
implicit val writes = Json.writes[User]
8+
implicit val writes: play.api.libs.json.OWrites[models.User] =
9+
Json.writes[User]
910
}

play-scala/rest-api/app/controllers/TodoListController.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ class TodoListController @Inject() (
1414
todoList += TodoListItem(1, "test", true)
1515
todoList += TodoListItem(2, "some other value", false)
1616

17-
implicit val todoListJson = Json.format[TodoListItem]
18-
implicit val newTodoListJson = Json.format[NewTodoListItem]
17+
implicit val todoListJson: play.api.libs.json.OFormat[models.TodoListItem] =
18+
Json.format[TodoListItem]
19+
implicit val newTodoListJson
20+
: play.api.libs.json.OFormat[models.NewTodoListItem] =
21+
Json.format[NewTodoListItem]
1922

2023
// curl localhost:9000/todo
2124
def getAll(): Action[AnyContent] = Action {

scala-2-modules/scala2-core/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
- [Introduction to Macros in Scala 2](https://www.baeldung.com/scala/scala2-macros)
99
- [Demystifying View and Context Bounds](https://www.baeldung.com/scala/view-context-bounds)
1010
- [Introduction to Scala](https://www.baeldung.com/scala/scala-intro)
11-
- [Exception Handling in Scala](https://www.baeldung.com/scala/exception-handling)
11+
- [Exception Handling in Scala](https://www.baeldung.com/scala/exception-handling)
12+
- [Usages of Underscore (_) in Scala](https://www.baeldung.com/scala/underscore)

scala-2-modules/scala2-core/src/main/scala-2/com/baeldung/scala/uniontypes/ArbitraryArityUnionType.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ object ArbitraryArityUnionType extends App {
2525

2626
sealed trait AOrB[A, B]
2727
object AOrB {
28-
implicit def aInstance[A, B](a: A) = new AOrB[A, B] {}
29-
implicit def bInstance[A, B](b: B) = new AOrB[A, B] {}
28+
implicit def aInstance[A, B](a: A): AOrB[A, B] = new AOrB[A, B] {}
29+
implicit def bInstance[A, B](b: B): AOrB[A, B] = new AOrB[A, B] {}
3030
}
3131

3232
def isIntOrString[T <% String AOrB Int](t: T): String = t match {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.baeldung.scala.underscore
22

3-
import com.baeldung.scala.underscore.UnderscoreUsages._
43
import org.scalatest.matchers.should.Matchers
54
import org.scalatest.wordspec.AnyWordSpec
5+
import UnderscoreUsages._
6+
67
class UnderscoreUsagesUnitTest extends AnyWordSpec with Matchers {
78

89
"The underscore" should {
@@ -48,7 +49,7 @@ class UnderscoreUsagesUnitTest extends AnyWordSpec with Matchers {
4849
b shouldBe "b"
4950

5051
text = "a,b,c,d,e"
51-
val Array(a2, _*) = text.split(",")
52+
val Array(a2, _*) = text.split(","): @unchecked
5253
a2 shouldBe "a"
5354

5455
val Array(a3, b3, _, d, e) = text.split(",")

scala-2-modules/scala2-libraries/src/main/scala-2/com/baeldung/cache/service/SyncQueryCustomMemoizeKeyService.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ object GuavaCacheCustomMemoizationKeyConfig {
2828
val memoizedUnderlyingCustomKeyGuavaCache =
2929
CacheBuilder.newBuilder().maximumSize(10000L).build[String, Entry[User]]
3030

31-
implicit val customKeyCacheConfig = CacheConfig(memoization =
32-
MemoizationConfig(toStringConverter = CustomKeyGenerator)
33-
)
31+
implicit val customKeyCacheConfig: scalacache.CacheConfig =
32+
CacheConfig(memoization =
33+
MemoizationConfig(toStringConverter = CustomKeyGenerator)
34+
)
3435

3536
implicit val guavaCache: Cache[User] = GuavaCache(
3637
memoizedUnderlyingCustomKeyGuavaCache

scala-2-modules/scala2-libraries/src/main/scala-2/com/baeldung/scala/pureconfig/Configs.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ object Protocol {
1818
}
1919

2020
object impl {
21-
implicit val localDateConvert = localDateConfigConvert(
22-
DateTimeFormatter.ISO_DATE
23-
)
24-
implicit val localDateTimeConvert = localDateTimeConfigConvert(
25-
DateTimeFormatter.ISO_DATE_TIME
26-
)
21+
implicit val localDateConvert: pureconfig.ConfigConvert[java.time.LocalDate] =
22+
localDateConfigConvert(
23+
DateTimeFormatter.ISO_DATE
24+
)
25+
implicit val localDateTimeConvert
26+
: pureconfig.ConfigConvert[java.time.LocalDateTime] =
27+
localDateTimeConfigConvert(
28+
DateTimeFormatter.ISO_DATE_TIME
29+
)
2730
}
2831

2932
final case class Port(number: Int) extends AnyVal

scala-2-modules/scala2-libraries/src/test/scala-2/com/baeldung/scala/shapeless/ShapelessUnitTest.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ class ShapelessUnitTest extends AnyWordSpec with Matchers {
138138
"calculate length of variant input types" in {
139139
import shapeless._
140140
object polyLength extends Poly1 {
141-
implicit val listCase = at[List[Int]](i => i.length)
142-
implicit val stringCase = at[String](d => d.length)
143-
implicit val arrayCase = at[Array[Int]](d => d.length)
141+
implicit val listCase: polyLength.Case.Aux[List[Int], Int] =
142+
at[List[Int]](i => i.length)
143+
implicit val stringCase: polyLength.Case.Aux[String, Int] =
144+
at[String](d => d.length)
145+
implicit val arrayCase: polyLength.Case.Aux[Array[Int], Int] =
146+
at[Array[Int]](d => d.length)
144147
}
145148

146149
val list = List(1, 2) :: "123" :: Array(1, 2, 3, 4) :: HNil

scala-akka-2/src/main/scala-2/com/baeldung/scala/akka/http/MovieServer.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import scala.util._
1313

1414
object MovieServer extends App {
1515

16-
implicit val system = ActorSystem("MoviesServer")
16+
implicit val system: akka.actor.ActorSystem = ActorSystem("MoviesServer")
1717
val movieService = new MovieService()
18-
implicit val movieFormat = jsonFormat3(Movie)
18+
implicit val movieFormat
19+
: spray.json.RootJsonFormat[com.baeldung.scala.akka.http.Movie] =
20+
jsonFormat3(Movie)
1921

2022
val route = path("movies" / "heartbeat") {
2123
get {

scala-akka-3/src/test/scala/com/baeldung/scala/akka/TestServiceUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestServiceUnitTest
1010
with BeforeAndAfterAll
1111
with Matchers {
1212
val testKit = ActorTestKit()
13-
implicit val system = testKit.system
13+
implicit val system: akka.actor.typed.ActorSystem[Nothing] = testKit.system
1414

1515
// responsible for shutting down the ActorSystem
1616
override def afterAll(): Unit = testKit.shutdownTestKit()

scala-akka-3/src/test/scala/com/baeldung/scala/akka/UnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class TrafficLightTestFutUnitTest extends TestServiceUnitTest {
110110
import scala.concurrent.duration._
111111
val sender = testKit.spawn(TrafficLight(), "traffic")
112112
val duration = 300.millis
113-
implicit val timeout = Timeout(duration)
113+
implicit val timeout: akka.util.Timeout = Timeout(duration)
114114

115115
val signalFut =
116116
sender.ask(replyTo => TrafficLight.SignalCommand.GetSignal(replyTo))

scala-akka/src/main/scala-2/com/baeldung/scala/akka/alpakka/Configs.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import akka.stream.ActorMaterializer
55

66
object Configs {
77

8-
implicit val actorSystem = ActorSystem("Alpakka")
9-
implicit val materializer = ActorMaterializer()
8+
implicit val actorSystem: akka.actor.ActorSystem = ActorSystem("Alpakka")
9+
implicit val materializer: akka.stream.ActorMaterializer = ActorMaterializer()
1010

1111
val filePath = "vehicle_data.log"
1212

scala-core-collections-modules/scala-core-collections-3/src/main/scala/com/baeldung/scala/commoncollections/ScalaCollections.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object ScalaCollections {
1010

1111
val numbersListWithOperator: List[Int] = 1 :: 2 :: 3 :: 4 :: Nil
1212
val emptyListWithNil: List[Int] = Nil
13-
val x :: xs = numbersList
13+
val x :: xs = numbersList: @unchecked
1414

1515
// Scala Set
1616
val emptySet: Set[Int] = Set()

scala-core-modules/scala-core-2/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ This module contains articles about Scala's core features.
99
- [Futures and Promises in Scala](https://www.baeldung.com/scala/futures-promises)
1010
- [Named and Default Arguments in Scala](https://www.baeldung.com/scala/named-default-arguments)
1111
- [Self-Type Annotation in Scala](https://www.baeldung.com/scala/self-type-annotation)
12-
- [Usages of Underscore (_) in Scala](https://www.baeldung.com/scala/underscore)
1312
- [A DSL for Writing “20 seconds” in Scala](https://www.baeldung.com/scala/dsl-writing-20-seconds)
1413
- [Error Handling in Scala](https://www.baeldung.com/scala/error-handling)
1514
- [Higher-Kinded Types](https://www.baeldung.com/scala/higher-kinded-types)

scala-core-modules/scala-core-2/src/main/scala/com/baeldung/scala/forcomprehension/ForComprehension.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object ForComprehension {
5656
def foreach(f: A => Unit): Unit = f(result)
5757
def map[B](f: A => B): Result[B] = Result(f(result))
5858
def flatMap[B](f: A => Result[B]): Result[B] = f(result)
59-
def withFilter(f: A => Boolean): Result[_] =
59+
def withFilter(f: A => Boolean): Result[?] =
6060
if (f(result)) this else EmptyResult
6161
}
6262

scala-core-modules/scala-core-3/src/main/scala/com/baeldung/scala/accessmodifiers/Figure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package com.baeldung.scala.accessmodifiers
33
import java.util.UUID.randomUUID
44

55
abstract class Figure {
6-
private[this] val code =
6+
private val code =
77
randomUUID.toString // accessible in the scope of the object-only
88
def printCode: Unit = println(s"$code") // public access
99

1010
protected[accessmodifiers] val color: String // accessible in the scope of the package
11-
protected[this] val lineWidth: Int // accessible for instances of this class and its subclasses instances
11+
protected val lineWidth: Int // accessible for instances of this class and its subclasses instances
1212

1313
protected val topPoint: Double // accessible in the scope of the class and subclasses
1414
protected val rightMostPoint: Double

scala-core-modules/scala-core-3/src/main/scala/com/baeldung/scala/iteratorsvsstreamsvsviews/NonStrictDataStructures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object NonStrictDataStructures {
88
val stream = data.toStream
99
// todo: check if this is ok, better to separate into separate module
1010
// val view: AnyRef with SeqView[Int, Seq[Int]] = data.view
11-
val view: AnyRef with SeqView[Int] = data.view
11+
val view: AnyRef & SeqView[Int] = data.view
1212
}
1313

1414
case class Factorial() {

scala-core-modules/scala-core-3/src/main/scala/com/baeldung/scala/typecasts/TypeErasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ object TypeErasure {
1313

1414
// Simply function that converts a variable number of values to a List of that type
1515
def convertValuesToList[T](values: T*): List[T] = {
16-
List[T](values: _*)
16+
List[T](values*)
1717
}
1818
}

scala-core-modules/scala-core-3/src/test/scala/com/baeldung/scala/typecasts/TypeErasureUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TypeErasureUnitTest extends AnyWordSpec with Matchers {
3939
"work with varargs" in {
4040
def varargFn(str: String*) = str.length
4141
val input = Seq("Hello", "World")
42-
assert(varargFn(input: _*) == 2)
42+
assert(varargFn(input*) == 2)
4343
}
4444
}
4545
}

scala-core-modules/scala-core-5/src/main/scala/com/baeldung/scala/adt/Examples.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package com.baeldung.scala.adt
22

33
object Examples {
44
sealed trait Color
5-
final case object White extends Color
6-
final case object Black extends Color
5+
case object White extends Color
6+
case object Black extends Color
77

88
sealed trait Name
9-
final case object Pawn extends Name
10-
final case object Rook extends Name
11-
final case object Knight extends Name
12-
final case object Bishop extends Name
13-
final case object Queen extends Name
14-
final case object King extends Name
9+
case object Pawn extends Name
10+
case object Rook extends Name
11+
case object Knight extends Name
12+
case object Bishop extends Name
13+
case object Queen extends Name
14+
case object King extends Name
1515

1616
case class ChessPiece(color: Color, name: Name)
1717

@@ -25,9 +25,9 @@ object Examples {
2525
}
2626

2727
sealed trait SemaphoreColor
28-
final case object Green extends SemaphoreColor
29-
final case object Amber extends SemaphoreColor
30-
final case object Red extends SemaphoreColor
28+
case object Green extends SemaphoreColor
29+
case object Amber extends SemaphoreColor
30+
case object Red extends SemaphoreColor
3131

3232
trait Feline
3333
trait Animal

scala-core-modules/scala-core-6/src/main/scala/com/baeldung/scala/functions/Functions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ object Functions {
3535
// getNameLengthDef.andThen(multiplyByTwoDef) //doesn't compile
3636

3737
/** Method to Function value */
38-
val getNameLengthDefFnValue = getNameLengthDef _
39-
val multiplyByTwoDefFnValue = multiplyByTwoDef _
38+
val getNameLengthDefFnValue = getNameLengthDef
39+
val multiplyByTwoDefFnValue = multiplyByTwoDef
4040

4141
getNameLengthDefFnValue.andThen(multiplyByTwoDefFnValue) // compiles
4242

scala-core-modules/scala-core-7/src/main/scala/com/baeldung/scala/productserializable/ColorInference.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object ColorV2 {
1414

1515
object Inference {
1616
def isError: Boolean = true
17-
val consoleColor: Product with Serializable with Color =
17+
val consoleColor: Product & Serializable & Color =
1818
if (isError) Color.Red else Color.Green
1919

2020
val consoleColorV2: Color = if (isError) Color.Red else Color.Green

scala-core-modules/scala-core-7/src/test/scala/com/baeldung/scala/arrays/CopyAnArrayToAnotherUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CopyAnArrayToAnotherUnitTest extends AnyFlatSpec with Matchers {
77
val array1 = Array(1, 2, 3, 4)
88

99
"splat operator" should "copy an entire array to another" in {
10-
var array2 = Array(array1: _*)
10+
var array2 = Array(array1*)
1111
array1(1) should be(array2(1))
1212
array1 should not be (array2)
1313

scala-core-modules/scala-core-7/src/test/scala/com/baeldung/scala/arrays/InitializeAnArrayUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class InitializeAnArrayUnitTest extends AnyFlatSpec with Matchers {
3030

3131
"splat operator" should "copy an entire list to an array" in {
3232
var list = List(1, 2, 3, 4)
33-
var array = Array[Int](list: _*)
33+
var array = Array[Int](list*)
3434

3535
array(1) should be(list(1))
3636
array.length should be(4)

scala-core-modules/scala-core-8/src/main/scala/com/baeldung/scala/braces/NoParenthesis.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ object NoParenthesis extends App {
99
// greet "Alice"
1010

1111
// But this works and it equivalent to greet("Alice")
12-
this greet "Alice"
12+
this `greet` "Alice"
1313

1414
}

scala-core-modules/scala-core-8/src/test/scala/com/baeldung/scala/reverselists/ListReverserUnitTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
99

1010
import ListReverser._
1111

12-
def testReverseSmallList(f: Seq[_] => Seq[_]): Assertion = {
12+
def testReverseSmallList(f: Seq[?] => Seq[?]): Assertion = {
1313
val list = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
1414
val expectedReversedList = List(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
1515
val actualReversedList = f(list)
1616
assertResult(expectedReversedList)(actualReversedList)
1717
}
1818

19-
def testReverseBigList(f: Seq[_] => Seq[_]): Assertion = {
19+
def testReverseBigList(f: Seq[?] => Seq[?]): Assertion = {
2020
val n = 100_000
2121
val vector: Vector[String] =
2222
(0 to n).foldLeft(Vector.empty[String])((v, _) =>
@@ -29,7 +29,7 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
2929
}
3030

3131
"The naive list reverser" should {
32-
val reversingFunction: Seq[_] => Seq[_] = naiveRecursiveReverse
32+
val reversingFunction: Seq[?] => Seq[?] = naiveRecursiveReverse
3333

3434
"reverse small lists" in {
3535
testReverseSmallList(reversingFunction)
@@ -41,7 +41,7 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
4141
}
4242

4343
"The tail-recursive list reverser" should {
44-
val reversingFunction: Seq[_] => Seq[_] = tailRecursiveReverse
44+
val reversingFunction: Seq[?] => Seq[?] = tailRecursiveReverse
4545

4646
"reverse small lists" in {
4747
testReverseSmallList(reversingFunction)
@@ -53,7 +53,7 @@ class ListReverserUnitTest extends AnyWordSpec with BeforeAndAfterEach {
5353
}
5454

5555
"The folding list reverser" should {
56-
val reversingFunction: Seq[_] => Seq[_] = foldBasedReverse
56+
val reversingFunction: Seq[?] => Seq[?] = foldBasedReverse
5757

5858
"reverse small lists" in {
5959
testReverseSmallList(reversingFunction)

scala-core-modules/scala-core-9/src/test/scala/com/baeldung/scala/classT/ClassTUnitTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ClassTUnitTest extends AnyFlatSpec with Matchers {
1919
)
2020

2121
// Instantiate the class with arguments
22-
Some(constructor.newInstance(args: _*).asInstanceOf[T])
22+
Some(constructor.newInstance(args*).asInstanceOf[T])
2323
} catch {
2424
case e: Exception =>
2525
println(s"Error creating instance of ${clazz.getName}: ${e.getMessage}")
@@ -37,7 +37,7 @@ class ClassTUnitTest extends AnyFlatSpec with Matchers {
3737

3838
"createInstance with .getClass" should "successfully create another instance of Person" in {
3939
val dummyPerson = new Person("Dummy")
40-
val personClass: Class[_ <: Person] = dummyPerson.getClass
40+
val personClass: Class[? <: Person] = dummyPerson.getClass
4141
val personInstance = createInstance(personClass, Array("Jane Doe": AnyRef))
4242

4343
personInstance should not be empty
@@ -46,7 +46,7 @@ class ClassTUnitTest extends AnyFlatSpec with Matchers {
4646

4747
"createInstance with .getClass" should "use the type of the variable to bound the type" in {
4848
val dummyPerson: Object = new Person("Dummy")
49-
val personClass: Class[_ <: AnyRef] = dummyPerson.getClass
49+
val personClass: Class[? <: AnyRef] = dummyPerson.getClass
5050
val personInstance = createInstance(personClass, Array("Jane Doe": AnyRef))
5151

5252
personInstance should not be empty

0 commit comments

Comments
 (0)