Skip to content

Commit dcb5e8d

Browse files
author
Dean Wampler
committed
Scala 3.0.1, with the simplification of given syntax.
1 parent 386cd2d commit dcb5e8d

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
val scala3 = "3.0.0"
1+
val scala3 = "3.0.1"
22
lazy val root = project
33
.in(file("."))
44
.settings(

src/main/scala/progscala3/contexts/json/JSONBuilder.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ object JSONBuilder:
102102
* are _witnesses_, constraining the allowed types of JSON values. Note that
103103
* there is nothing to implement in the trait, but we have to use the `with {}`
104104
* clauses to make these definitions concrete.
105+
* NOTE: Scala 3.0.0 requires "given ValidJSONValue[Int] with {}", while 3.0.1
106+
* removed the need for "with {}", but you have to add the "()".
105107
*/
106108
sealed trait ValidJSONValue[T <: Matchable]
107-
given ValidJSONValue[Int] with {}
108-
given ValidJSONValue[Double] with {}
109-
given ValidJSONValue[String] with {}
110-
given ValidJSONValue[Boolean] with {}
111-
given ValidJSONValue[JSONObject] with {}
112-
given ValidJSONValue[JSONArray] with {}
109+
given ValidJSONValue[Int]()
110+
given ValidJSONValue[Double]()
111+
given ValidJSONValue[String]()
112+
given ValidJSONValue[Boolean]()
113+
given ValidJSONValue[JSONObject]()
114+
given ValidJSONValue[JSONArray]()
113115

114116

115117
/**

src/script/scala/progscala3/contexts/GivenImports.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ trait Marker[T]
2323
object O2:
2424
class C1
2525
given C1 = C1()
26-
given Marker[Int] with {} // <1>
27-
given Marker[List[?]] with {} // <2>
26+
// In Scala 3.0.0, the following has to be written: given Marker[Int] with {}
27+
given Marker[Int]() // <1>
28+
given Marker[List[?]]() // <2>
2829

2930
import O2.{given Marker[?]} // Import all given Markers
3031
import O2.{given Marker[Int]} // Import just the Marker[Int]

src/script/scala/progscala3/contexts/UsingTypeErasureWorkaround.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
object O2:
55
trait Marker[T] // <1>
6-
given IntMarker: Marker[Int] with {}
7-
given StringMarker: Marker[String] with {}
6+
// In Scala 3.0.0, the following has to be written:
7+
// given IntMarker: Marker[Int] with {}
8+
given IntMarker: Marker[Int]()
9+
given StringMarker: Marker[String]()
810

911
def m(is: Seq[Int])(using IntMarker.type): Int = is.sum // <2>
1012
def m(ss: Seq[String])(using StringMarker.type): Int = ss.length

src/script/scala/progscala3/meta/compiletime/SummonAll.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import scala.compiletime.summonAll
33

44
trait C; trait D; trait E
5-
given c: C with {}
6-
given d: D with {}
5+
// In Scala 3.0.0, the following has to be written: given c: C with {}
6+
given c: C()
7+
given d: D()
78

89
summonAll[C *: D *: EmptyTuple]
910
summonAll[C *: D *: E *: EmptyTuple] // <1>

src/script/scala/progscala3/meta/compiletime/SummonFrom.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ inline def trySummonFrom(label: String, expected: Int): Unit = // <1>
1414
def tryNone = trySummonFrom("tryNone:", 0) // <2>
1515

1616
def tryA = // <3>
17-
given A with {}
17+
// In Scala 3.0.0, the following has to be written: given A with {}
18+
given A()
1819
trySummonFrom("tryA:", 1)
1920

2021
def tryB =
21-
given B with {}
22+
given B()
2223
trySummonFrom("tryB:", 2)
2324

2425
def tryAB =
25-
given A with {}
26-
given B with {}
26+
given A()
27+
given B()
2728
trySummonFrom("tryAB:", 1)
2829

2930
tryNone; tryA; tryB; tryAB

0 commit comments

Comments
 (0)