Skip to content

Commit 3555838

Browse files
committed
resolved requested changes
1 parent 20a7533 commit 3555838

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ object ScriptSourceFile {
2323
private val headerStarts = List("#!", "::#!")
2424

2525
/** Return true if has a script header */
26-
def hasScriptHeader(content: Array[Char]): Boolean = {
27-
headerStarts exists (content startsWith _)
28-
}
26+
def hasScriptHeader(content: Array[Char]): Boolean =
27+
headerStarts.exists(content.startsWith(_))
2928

3029
def apply(file: AbstractFile, content: Array[Char]): SourceFile = {
3130
/** Length of the script header from the given content, if there is one.
@@ -40,14 +39,14 @@ object ScriptSourceFile {
4039
}
4140
else 0
4241

43-
// overwrite hash-bang lines with all spaces
42+
// overwrite hash-bang lines with all spaces to preserve line numbers
4443
val hashBangLines = content.take(headerLength).mkString.split("\\r?\\n")
4544
if hashBangLines.nonEmpty then
4645
for i <- 0 until headerLength do
4746
content(i) match {
48-
case '\r' | '\n' =>
49-
case _ =>
50-
content(i) = ' '
47+
case '\r' | '\n' =>
48+
case _ =>
49+
content(i) = ' '
5150
}
5251

5352
new SourceFile(file, content) {
@@ -266,15 +265,16 @@ object SourceFile {
266265
* if filename extension is not .scala and has a script header.
267266
*/
268267
def isScript(file: AbstractFile, content: Array[Char]): Boolean =
269-
if file.hasExtension(".scala") then
270-
false
271-
else
272-
ScriptSourceFile.hasScriptHeader(content)
268+
ScriptSourceFile.hasScriptHeader(content)
273269

274270
def apply(file: AbstractFile, codec: Codec): SourceFile =
275271
// see note above re: Files.exists is remarkably slow
276-
val chars = try new String(file.toByteArray, codec.charSet).toCharArray
277-
catch case _: java.nio.file.NoSuchFileException => Array[Char]()
272+
val chars =
273+
try
274+
new String(file.toByteArray, codec.charSet).toCharArray
275+
catch
276+
case _: java.nio.file.NoSuchFileException => Array[Char]()
277+
278278
if isScript(file, chars) then
279279
ScriptSourceFile(file, chars)
280280
else

compiler/src/dotty/tools/scripting/Main.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ object Main:
7272
import dotty.tools.io.{Jar, Directory}
7373
val jar = new Jar(jarPath)
7474
val writer = jar.jarWriter(manifestAttributes:_*)
75-
writer.writeAllFrom(Directory(outDir))
75+
try
76+
writer.writeAllFrom(Directory(outDir))
77+
finally
78+
writer.close()
7679
end writeJarfile
7780

7881
def pathsep = sys.props("path.separator")

0 commit comments

Comments
 (0)