Skip to content

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

Open
@Gedochao

Description

@Gedochao

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)
€

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingscalac compatibilityIssues tied with compatibility with the scalac (compiler) command.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions