Skip to content

Commit 5d176e5

Browse files
authored
Be more specific in return type of make and /. (#154)
This results in nicer and more expected return types: ```scala scala> os.root / "a" / "b" val res0: os.Path = /a/b ``` whereas in previous versions, it contained one or multiple `ThisType`. E.g. on Scala 3.2 ```scala scala> os.root / "a" / "b" val res0: os.root.ThisType#ThisType = /a/b ``` * Fixes #153 Pull request: #154
1 parent 224aae7 commit 5d176e5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

os/src/Path.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ trait SegmentedPath extends BasePath {
174174
*/
175175
def segments: IndexedSeq[String]
176176

177-
def /(chunk: PathChunk) = make(
177+
override def /(chunk: PathChunk): ThisType = make(
178178
segments.dropRight(chunk.ups) ++ chunk.segments,
179179
math.max(chunk.ups - segments.length, 0)
180180
)
@@ -259,7 +259,7 @@ class RelPath private[os] (segments0: Array[String], val ups: Int)
259259
val segments: IndexedSeq[String] = segments0.toIndexedSeq
260260
type ThisType = RelPath
261261
require(ups >= 0)
262-
protected[this] def make(p: Seq[String], ups: Int) = {
262+
override protected[this] def make(p: Seq[String], ups: Int): RelPath = {
263263
new RelPath(p.toArray[String], ups + this.ups)
264264
}
265265

@@ -323,8 +323,8 @@ class SubPath private[os] (val segments0: Array[String])
323323
extends FilePath with BasePathImpl with SegmentedPath {
324324
def lastOpt = segments.lastOption
325325
val segments: IndexedSeq[String] = segments0.toIndexedSeq
326-
type ThisType = SubPath
327-
protected[this] def make(p: Seq[String], ups: Int) = {
326+
override type ThisType = SubPath
327+
override protected[this] def make(p: Seq[String], ups: Int): SubPath = {
328328
require(ups == 0)
329329
new SubPath(p.toArray[String])
330330
}
@@ -454,11 +454,11 @@ class Path private[os] (val wrapped: java.nio.file.Path)
454454
def segments: Iterator[String] = wrapped.iterator().asScala.map(_.toString)
455455
def getSegment(i: Int): String = wrapped.getName(i).toString
456456
def segmentCount = wrapped.getNameCount
457-
type ThisType = Path
457+
override type ThisType = Path
458458

459459
def lastOpt = Option(wrapped.getFileName).map(_.toString)
460460

461-
def /(chunk: PathChunk): ThisType = {
461+
override def /(chunk: PathChunk): Path = {
462462
if (chunk.ups > wrapped.getNameCount) throw PathError.AbsolutePathOutsideRoot
463463
val resolved = wrapped.resolve(chunk.toString).normalize()
464464
new Path(resolved)

0 commit comments

Comments
 (0)