Skip to content

Close Files.lines stream #14379

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

Merged
merged 2 commits into from
Jan 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/test/dotty/tools/utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit
end assertThrows

def toolArgsFor(files: List[JPath], charset: Charset = UTF_8): List[String] =
files.flatMap(path => toolArgsParse(Files.lines(path, charset).limit(10).toScala(List)))
files.flatMap(path => toolArgsParse {
val stream = Files.lines(path, charset)
try stream.limit(10).toScala(List)
finally stream.close()
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally use scala.util.Using for this:

Suggested change
files.flatMap(path => toolArgsParse {
val stream = Files.lines(path, charset)
try stream.limit(10).toScala(List)
finally stream.close()
})
files.flatMap(path => toolArgsParse(Using(Files.lines(path, charset))(_.limit(10).toScala(List))))


// Inspect the first 10 of the given lines for compiler options of the form
// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.
Expand Down