Skip to content

Commit

Permalink
Rewrites are UTF-8 (#15622)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Sep 5, 2022
2 parents b5fea82 + 2085bfd commit 417f720
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala
Expand Up @@ -8,6 +8,9 @@ import collection.mutable
import scala.annotation.tailrec
import dotty.tools.dotc.reporting.Reporter

import java.io.OutputStreamWriter
import java.nio.charset.StandardCharsets.UTF_8

/** Handles rewriting of Scala2 files to Dotty */
object Rewrites {
private class PatchedFiles extends mutable.HashMap[SourceFile, Patches]
Expand Down Expand Up @@ -54,13 +57,11 @@ object Rewrites {
ds
}

def writeBack(): Unit = {
def writeBack(): Unit =
val chars = apply(source.underlying.content)
val bytes = new String(chars).getBytes
val out = source.file.output
out.write(bytes)
out.close()
}
val osw = OutputStreamWriter(source.file.output, UTF_8)
try osw.write(chars, 0, chars.length)
finally osw.close()
}

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

0 comments on commit 417f720

Please sign in to comment.