Commit f2937c3
committed
Fix broken dotty.tools.io.Path#parent
The previous implementation wrongly assumed that if
`jpath.normalize.getParent` returns null, then `jpath` must be a root.
However the null in this case really only means that no name elements
remain after normalization and the call to `getParent`. Since redundant
name elements such as "." and ".." may be removed by `normalize`, and
`getParent` may simply remove the last name element, there are cases
other than roots to consider, such as the current directory.
Some examples of broken behavior prior this commit:
scala> Path("./foo.txt").parent
val res0: dotty.tools.io.Directory = ./foo.txt // should be Directory(.)
scala> Path("foo.txt").parent
val res1: dotty.tools.io.Directory = foo.txt // should be Directory(.)
scala> Path(".").parent
val res4: dotty.tools.io.Directory = . // should be Directory(..)
The changes here are based in part on the Scala 2.13 implementation of
scala.reflect.io.Path#parent
Fixes #116441 parent f2f877c commit f2937c3
File tree
4 files changed
+41
-1
lines changed- compiler
- src/dotty/tools/io
- test/dotty/tools/io
- project/scripts
- tests/pos
4 files changed
+41
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
131 | 139 | | |
132 | 140 | | |
133 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments