VirtusLab / scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
https://scala-cli.virtuslab.org
Apache License 2.0
546 stars 127 forks source link

-encoding is not handled correctly for `.sc` scripts #1390

Open Gedochao opened 2 years ago

Gedochao commented 2 years ago

Version(s) 0.1.14

Describe the bug When running a script with non-UTF-8 encoding, even when the -encoding compiler param is passed, it is not respected.

To Reproduce

▶ cat script.sc
println("€")

▶ iconv -f UTF-8 -t CP1252 script.sc > script-CP-1252.sc   

▶ cat script-CP-1252.sc 
println("�")

▶ scala-cli script.sc
Compiling project (Scala 3.2.0, JVM)
Compiled project (Scala 3.2.0, JVM)
€

▶ scala-cli script-CP-1252.sc 
Compiling project (Scala 3.2.0, JVM)
Compiled project (Scala 3.2.0, JVM)
�

▶ scala-cli script-CP-1252.sc -O -encoding -O cp1252
Compiling project (Scala 3.2.0, JVM)
Compiled project (Scala 3.2.0, JVM)
�

Expected behaviour

▶ scala-cli script-CP-1252.sc -O -encoding -O cp1252
Compiling project (Scala 3.2.0, JVM)
Compiled project (Scala 3.2.0, JVM)
€

Additional context Discovered when spiking for #1310. This bug only happens with .sc scripts. .scala files are being handled correctly.

▶ cat Main.scala
object Main extends App {
  println("€")
}

▶ iconv -f UTF-8 -t CP1252 Main.scala > Main-CP-1252.scala

▶ scala-cli Main.scala
Compiling project (Scala 3.2.0, JVM)
Compiled project (Scala 3.2.0, JVM)
€

▶ scala-cli Main-CP-1252.scala -O -encoding -O cp1252
Compiling project (Scala 3.2.0, JVM)
Compiled project (Scala 3.2.0, JVM)
€
alexarchambault commented 2 years ago

In Scala CLI, for now, UTF-8 is assumed almost everywhere, yeah…