Skip to content

Commit 2004ec5

Browse files
committed
fix-#9026 eliminate .. in paths
1 parent 484e3c6 commit 2004ec5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Names.Name
1212
import StdNames.nme
1313
import util.Spans.Span
1414
import util.{SourceFile, SourcePosition}
15+
import scala.jdk.CollectionConverters._
1516
import collection.mutable
1617
import java.nio.file.Paths
1718

@@ -594,8 +595,20 @@ object ExtractSemanticDB:
594595

595596
def write(source: SourceFile, occurrences: List[SymbolOccurrence], symbolInfos: List[SymbolInformation])(using Context): Unit =
596597
def absolutePath(path: Path): Path = path.toAbsolutePath.normalize
598+
def common(root: Path, i1: java.util.Iterator[Path], i2: java.util.Iterator[Path]) =
599+
require(root != null)
600+
var res: Path = root
601+
var next: Path = null
602+
while
603+
i1.hasNext && i2.hasNext
604+
&& { next = i1.next; next } == i2.next
605+
do res = res.resolve(next)
606+
res
607+
end common
597608
val sourcePath = absolutePath(source.file.jpath)
598-
val sourceRoot = absolutePath(Paths.get(ctx.settings.sourceroot.value))
609+
val sourceRoot =
610+
val sourceRoot0 = absolutePath(Paths.get(ctx.settings.sourceroot.value))
611+
common(sourcePath.getRoot, sourcePath.iterator, sourceRoot0.iterator)
599612
val semanticdbTarget =
600613
val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
601614
absolutePath(

compiler/test/dotty/tools/dotc/core/tasty/CommentPicklingTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CommentPicklingTest {
8282
Directory.inTempDirectory { tmp =>
8383
val sourceFiles = sources.zipWithIndex.map {
8484
case (src, id) =>
85-
val path = tmp./(File("Src$id.scala")).toAbsolute
85+
val path = tmp./(File(s"Src$id.scala")).toAbsolute
8686
path.writeAll(src)
8787
path.toString
8888
}

0 commit comments

Comments
 (0)