8000 Enable Scala 3 migration mode · scala-graph/scala-graph@7cfc5d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cfc5d6

Browse files
committed
Enable Scala 3 migration mode
1 parent 1b7dc92 commit 7cfc5d6

File tree

14 files changed

+55
-34
lines changed

14 files changed

+55
-34
lines changed

build.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ val unusedImports = "-Wunused:imports"
9797

9898
lazy val defaultSettings_2_13 = Defaults.coreDefaultSettings ++ Seq(
9999
scalaVersion := Version.compiler_2_13,
100+
scalacOptions ++= Seq(
101+
"-Xsource:3",
102+
"-Xsource-features:case-apply-copy-access"
103+
),
100104
libraryDependencies ++= Seq(
101105
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
102106
"org.scalatestplus" %% "scalacheck-1-18" % "3.2.19.0" % Test

core/src/main/scala/scalax/collection/hyperedges/ordered/HyperEdge.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scalax.collection.generic.{
88
/** Undirected hyperedge with ends having sequence semantic with respect to equality.
99
*/
1010
@SerialVersionUID(-52)
11-
final case class HyperEdge[+N] private (override val ends: Several[N])
11+
final case class HyperEdge[+N](override val ends: Several[N])
1212
extends AbstractUnlabeledGenericHyperEdge[N, HyperEdge](ends)
1313
with OrderedEndpoints
1414
with HyperEdgeToString

core/src/test/scala/demo/GraphTestDemo.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object GraphTestDemo extends App {
9292
type IntDiGraph = Graph[Int, DiEdge[Int]]
9393
implicit val arbitraryTinyGraph: Arbitrary[Graph[Int, DiEdge[Int]]] = GraphGen.tinyConnectedIntDi[Graph](Graph)
9494

95-
val properTiny = forAll(arbitrary[IntDiGraph]) { g: IntDiGraph =>
95+
val properTiny = forAll(arbitrary[IntDiGraph]) { (g: IntDiGraph) =>
9696
g.order == GraphGen.TinyInt.order
9797
}
9898
properTiny.check()
@@ -111,7 +111,7 @@ object GraphTestDemo extends App {
111111
GraphGen.fromMetrics[Int, UnDiEdge[Int], Graph](Graph, Sparse_1000_Int, Set(UnDiEdge)).apply
112112
}
113113

114-
val properSparse = forAll(arbitrary[IntUnDiGraph]) { g: IntUnDiGraph =>
114+
val properSparse = forAll(arbitrary[IntUnDiGraph]) { (g: IntUnDiGraph) =>
115115
g.order == Sparse_1000_Int.order
116116
}
117117
properSparse.check()
@@ -149,7 +149,7 @@ object GraphTestDemo extends App {
149149
.apply
150150
}
151151

152-
val properMixedGraph = forAll(arbitrary[Mixed]) { g: Mixed =>
152+
val properMixedGraph = forAll(arbitrary[Mixed]) { (g: Mixed) =>
153153
g.order == MixedMetrics.order
154154
}
155155
properMixedGraph.check()
@@ -169,7 +169,7 @@ object GraphTestDemo extends App {
169169
implicit val arbitraryTinyGraph: Arbitrary[Graph[Int, DiEdge[Int]]] = GraphGen.tinyConnectedIntDi[Graph](Graph)
170170

171171
def `should conform to tiny metrics`: Unit =
172-
forAll(arbitrary[IntDiGraph]) { g: IntDiGraph =>
172+
forAll(arbitrary[IntDiGraph]) { (g: IntDiGraph) =>
173173
g.order should equal(GraphGen.TinyInt.order)
174174
}
175175
}

core/src/test/scala/scalax/collection/CycleSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private trait CycleMatcher[N, E <: Edge[N]] {
2020
protected type C = AnyGraph[N, E]#Cycle
2121

2222
def haveOneNodeSequenceOf(expected: Seq[N]*): Matcher[Option[C]] =
23-
Matcher { ns: Option[C] =>
23+
Matcher { (ns: Option[C]) =>
2424
val found: Seq[N] = ns match {
2525
case None => Seq()
2626
case Some(path) => path.nodes.toSeq.map(_.outer).toList
@@ -34,7 +34,7 @@ private trait CycleMatcher[N, E <: Edge[N]] {
3434
}
3535

3636
def beValid: Matcher[Option[C]] =
37-
Matcher { c: Option[C] =>
37+
Matcher { (c: Option[C]) =>
3838
def msg(key: String): String = s"$c $key valid"
3939
MatchResult(c.get.isValid, msg("is not"), msg("is"))
4040
}

core/src/test/scala/scalax/collection/EditingSpec.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ import scalax.collection.edges._
77
import scalax.collection.generic._
88
import scalax.collection.OuterImplicits._
99
import scalax.collection.config.GraphConfig
10+
import scalax.collection.immutable.Graph
11+
import scalax.collection.config.CoreConfig
1012

1113
/** Editing any kind of non-hypergraph with unlabeled edges including mixed graphs.
1214
*/
1315
class EditingSpec
1416
extends Suites(
1517
new EditingEdges,
1618
new Editing[immutable.Graph](new ConfigWrapper[immutable.Graph] {
17-
val companion = immutable.Graph
18-
val config = immutable.Graph.defaultConfig
19+
val companion: Graph.type = immutable.Graph
20+
val config: CoreConfig = immutable.Graph.defaultConfig
1921
}),
2022
new Editing[mutable.Graph](new ConfigWrapper[mutable.Graph] {
21-
val companion = mutable.Graph
22-
val config = mutable.Graph.defaultConfig
23+
val companion: mutable.Graph.type = mutable.Graph
24+
val config: CoreConfig = mutable.Graph.defaultConfig
2325
}),
2426
new EditingImmutable,
2527
new EditingMutable

core/src/test/scala/scalax/collection/MappingTypedSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MappingTypedSpec extends RefSpec with Matchers {
4242

4343
def `upcast nodes to another typed edge within the ADT`: Unit =
4444
TGraph(AConnector(a_1, a_1)) pipe { g =>
45-
g.mapBound[Node, Connector](_ => b_0_0, Connector) pipe { mapped =>
45+
g.mapBound[Node, Connector](_ => b_0_0, Connector.apply) pipe { mapped =>
4646
mapped.edges.head.outer shouldEqual Connector(b_0_0, b_0_0)
4747
}
4848
}

core/src/test/scala/scalax/collection/SerializableSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ protected object ScalaObjectSerialization extends App {
337337
def d = "MyDef"
338338
val v = "MyVal"
339339
}
340-
def inner = Inner
340+
def inner: Inner.type = Inner
341341
}
342342

343343
private trait MyTrait extends Base with Serializable {
@@ -346,7 +346,7 @@ protected object ScalaObjectSerialization extends App {
346346
def d = "MyDef"
347347
val v = "MyVal"
348348
}
349-
val inner = Inner
349+
val inner: Inner.type = Inner
350350
}
351351

352352
private class MyClass extends Base with Serializable {
@@ -355,7 +355,7 @@ protected object ScalaObjectSerialization extends App {
355355
def d = "MyDef"
356356
val v = "MyVal"
357357
}
358-
val inner = Inner
358+
val inner: Inner.type = Inner
359359
}
360360

361361
import ByteArraySerialization._

core/src/test/scala/scalax/collection/SetOpsSpec.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import scalax.collection.edges._
1111
import scalax.collection.generic.{Edge, GenericGraphCoreFactory}
1212

1313
import scalax.collection.visualization.Visualizer
14+
import scalax.collection.immutable.Graph
1415

1516
class SetOpsSpec
1617
extends Suites(
@@ -73,12 +74,12 @@ private class SetOps[CC[N, E <: Edge[N]] <: AnyGraph[N, E] with GraphLike[N, E,
7374
}
7475

7576
private class SetOpsImmutable extends RefSpec with Matchers with SetOpExamples[immutable.Graph] {
76-
protected val factory = immutable.Graph
77+
protected val factory: Graph.type = immutable.Graph
7778

7879
}
7980

8081
private class SetOpsMutable extends RefSpec with Matchers with SetOpExamples[mutable.Graph] {
81-
protected val factory = mutable.Graph
82+
protected val factory: mutable.Graph.type = mutable.Graph
8283

8384
private val iH = immutable.Graph.from(hEdges)
8485

core/src/test/scala/scalax/collection/generator/GraphGenSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class GraphGenSpec extends RefSpec with Matchers with ScalaCheckPropertyChecks {
6767
implicit val arbitraryGraph: Arbitrary[Graph[Int, DiEdge[Int]]] = GraphGen.tinyConnectedIntDi[Graph](Graph)
6868

6969
def `should conform to tiny metrics`: Unit =
70-
forAll(arbitrary[IntDiGraph]) { g: IntDiGraph =>
70+
forAll(arbitrary[IntDiGraph]) { (g: IntDiGraph) =>
7171
checkMetrics(g, GraphGen.TinyInt)
7272
}
7373
}
@@ -76,7 +76,7 @@ class GraphGenSpec extends RefSpec with Matchers with ScalaCheckPropertyChecks {
7676
implicit val arbitraryGraph: Arbitrary[Graph[Int, DiEdge[Int]]] = GraphGen.smallConnectedIntDi[Graph](Graph)
7777

7878
def `should conform to small metrics`: Unit =
79-
forAll(arbitrary[IntDiGraph]) { g: IntDiGraph =>
79+
forAll(arbitrary[IntDiGraph]) { (g: IntDiGraph) =>
8080
checkMetrics(g, GraphGen.SmallInt)
8181
}
8282
}

core/src/test/scala/scalax/collection/labeled/TraversalSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ final private class Traversal[G[N, E <: Edge[N]] <: AnyGraph[N, E] with GraphLik
245245
shp4.get.edges.toList should be(List(flight("UA 8840"), flight("LH 1480")))
246246

247247
val visited = MSet[g.EdgeT]()
248-
(g get jfc).innerEdgeTraverser.shortestPathTo(g get lhr) { e: g.EdgeT =>
248+
(g get jfc).innerEdgeTraverser.shortestPathTo(g get lhr) { (e: g.EdgeT) =>
249249
visited += e
250250
}
251251
val visitedSorted = visited.toList.sortWith((a: g.EdgeT, b: g.EdgeT) => a.flightNo < b.flightNo)

core/src/test/scala/scalax/time/MicroBenchmark.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object MicroBenchmark {
3535
def toFloat(x: NanoSecond) = x.value.toFloat
3636
def toDouble(x: NanoSecond) = x.value.toDouble
3737
def compare(x: NanoSecond, y: NanoSecond) = num.compare(x, y)
38-
def parseString(str: String) = throw new UnsupportedOperationException
38+
def parseString(str: String): Nothing = throw new UnsupportedOperationException
3939
}
4040

4141
sealed abstract class MeasurementResult[A](result: A) {

json/src/main/scala/scalax/collection/io/json/descriptor/EdgeDescriptor.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class EdgeDescriptor[N, E <: AnyEdge[N]](
8282

8383
def extract(jsonEdge: JValue): EdgeParameters = jsonEdge.extract[EdgeParameters]
8484

85-
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]) = {
85+
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]): EdgeParameters = {
8686
val (n1, n2) = (edge.node1, edge.node2)
8787
EdgeParameters(descriptor.nodeDescriptor(n1) id n1, descriptor.nodeDescriptor(n2) id n2)
8888
}
@@ -110,7 +110,7 @@ abstract class LEdgeDescriptor[N, E <: AnyEdge[N], L](
110110

111111
def extract(jsonEdge: JValue): LEdgeParameters[L] = jsonEdge.extract[LEdgeParameters[L]]
112112

113-
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]) =
113+
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]): LEdgeParameters[Any] =
114114
LEdgeParameters(
115115
descriptor.nodeDescriptor(edge.node1) id edge.node1,
116116
descriptor.nodeDescriptor(edge.node2) id edge.node2,
@@ -136,7 +136,7 @@ class HyperEdgeDescriptor[N, E <: AbstractHyperEdge[N]](
136136

137137
def extract(jsonEdge: JValue): HyperEdgeParameters = jsonEdge.extract[HyperEdgeParameters]
138138

139-
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]) =
139+
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]): HyperEdgeParameters =
140140
HyperEdgeParameters(nodeIds(edge, descriptor))
141141
}
142142

@@ -160,7 +160,7 @@ abstract class LHyperEdgeDescriptor[N, E <: AbstractHyperEdge[N], L](
160160

161161
def extract(jsonEdge: JValue): LHyperEdgeParameters[L] = jsonEdge.extract[LHyperEdgeParameters[L]]
162162

163-
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]) =
163+
protected def toParameters(edge: E)(implicit descriptor: Descriptor[N]): LHyperEdgeParameters[Any] =
164164
LHyperEdgeParameters(nodeIds(edge, descriptor), label(edge))
165165
}
166166

json/src/main/scala/scalax/collection/io/json/descriptor/predefined/edgeDescriptors.scala

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait PredefinedEdgeDescriptor extends PredefinedEdgeDescriptorBase {
2828
}
2929

3030
case object UnDi extends PredefinedEdgeDescriptor {
31-
def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = None) =
31+
def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = None): EdgeDescriptor[N, UnDiEdge[N]] =
3232
new EdgeDescriptor[N, UnDiEdge[N]](
3333
UnDiEdge.apply,
3434
check[EdgeParameters](customSerializer),
@@ -38,7 +38,9 @@ case object UnDi extends PredefinedEdgeDescriptor {
3838
}
3939

4040
case object WUnDi extends PredefinedEdgeDescriptor {
41-
def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer) =
41+
def descriptor[N](
42+
customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer
43+
): LEdgeDescriptor[N, WUnDiEdge[N], Double] =
4244
new LEdgeDescriptor[N, WUnDiEdge[N], Double](
4345
WUnDiEdge.apply,
4446
Double.MaxValue,
@@ -51,7 +53,9 @@ case object WUnDi extends PredefinedEdgeDescriptor {
5153
}
5254

5355
case object MultiWUnDi extends PredefinedEdgeDescriptor {
54-
override def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer) =
56+
override def descriptor[N](
57+
customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer
58+
): LEdgeDescriptor[N, MultiWUnDiEdge[N], Double] =
5559
new LEdgeDescriptor[N, MultiWUnDiEdge[N], Double](
5660
MultiWUnDiEdge.apply,
5761
Double.MaxValue,
@@ -64,12 +68,16 @@ case object MultiWUnDi extends PredefinedEdgeDescriptor {
6468
}
6569

6670
case object Di extends PredefinedEdgeDescriptor {
67-
override def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = None) =
71+
override def descriptor[N](
72+
customSerializer: Option[Serializer[_ <: Parameters]] = None
73+
): EdgeDescriptor[N, DiEdge[N]] =
6874
new EdgeDescriptor[N, DiEdge[N]](DiEdge.apply, check(customSerializer), Nil, caseObjectBasedTypeId)
6975
}
7076

7177
case object WDi extends PredefinedEdgeDescriptor {
72-
override def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer) =
78+
override def descriptor[N](
79+
customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer
80+
): LEdgeDescriptor[N, WDiEdge[N], Double] =
7381
new LEdgeDescriptor[N, WDiEdge[N], Double](
7482
WDiEdge.apply,
7583
Double.MaxValue,
@@ -82,7 +90,9 @@ case object WDi extends PredefinedEdgeDescriptor {
8290
}
8391

8492
case object MultiWDi extends PredefinedEdgeDescriptor {
85-
override def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer) =
93+
override def descriptor[N](
94+
customSerializer: Option[Serializer[_ <: Parameters]] = some.wEdgeSerializer
95+
): LEdgeDescriptor[N, MultiWDiEdge[N], Double] =
8696
new LEdgeDescriptor[N, MultiWDiEdge[N], Double](
8797
MultiWDiEdge.apply,
8898
Double.MaxValue,
@@ -95,7 +105,9 @@ case object MultiWDi extends PredefinedEdgeDescriptor {
95105
}
96106

97107
case object Hyper extends PredefinedEdgeDescriptor {
98-
override def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = some.hyperEdgeSerializer) =
108+
override def descriptor[N](
109+
customSerializer: Option[Serializer[_ <: Parameters]] = some.hyperEdgeSerializer
110+
): HyperEdgeDescriptor[N, HyperEdge[N]] =
99111
new HyperEdgeDescriptor[N, HyperEdge[N]](
100112
HyperEdge.apply,
101113
check[HyperEdgeParameters](customSerializer),
@@ -105,7 +117,9 @@ case object Hyper extends PredefinedEdgeDescriptor {
105117
}
106118

107119
case object DiHyper extends PredefinedEdgeDescriptor {
108-
override def descriptor[N](customSerializer: Option[Serializer[_ <: Parameters]] = some.diHyperEdgeSerializer) =
120+
override def descriptor[N](
121+
customSerializer: Option[Serializer[_ <: Parameters]] = some.diHyperEdgeSerializer
122+
): DiHyperEdgeDescriptor[N, DiHyperEdge[N]] =
109123
new DiHyperEdgeDescriptor[N, DiHyperEdge[N]](DiHyperEdge.apply, check(customSerializer), Nil, caseObjectBasedTypeId)
110124
}
111125

json/src/main/scala/scalax/collection/io/json/exp/Export.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Export[N, E <: Edge[N]](
1818

1919
def jsonASTNodes: JField = {
2020
val classNodesMap =
21-
graph.nodes.toOuter groupBy { a: Any =>
21+
graph.nodes.toOuter groupBy { (a: Any) =>
2222
val clazz = a.asInstanceOf[AnyRef].getClass
2323
if (simpleClassNames) clazz.getSimpleName
2424
else clazz.getName

0 commit comments

Comments
 (0)
0