Skip to content

Commit 417f720

Browse files
authored
Rewrites are UTF-8 (#15622)
2 parents b5fea82 + 2085bfd commit 417f720

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import collection.mutable
88
import scala.annotation.tailrec
99
import dotty.tools.dotc.reporting.Reporter
1010

11+
import java.io.OutputStreamWriter
12+
import java.nio.charset.StandardCharsets.UTF_8
13+
1114
/** Handles rewriting of Scala2 files to Dotty */
1215
object Rewrites {
1316
private class PatchedFiles extends mutable.HashMap[SourceFile, Patches]
@@ -54,13 +57,11 @@ object Rewrites {
5457
ds
5558
}
5659

57-
def writeBack(): Unit = {
60+
def writeBack(): Unit =
5861
val chars = apply(source.underlying.content)
59-
val bytes = new String(chars).getBytes
60-
val out = source.file.output
61-
out.write(bytes)
62-
out.close()
63-
}
62+
val osw = OutputStreamWriter(source.file.output, UTF_8)
63+
try osw.write(chars, 0, chars.length)
64+
finally osw.close()
6465
}
6566

6667
/** If -rewrite is set, record a patch that replaces the range

0 commit comments

Comments
 (0)