Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrites are UTF-8 #15622

Merged
merged 2 commits into from Sep 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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