-
Notifications
You must be signed in to change notification settings - Fork 86
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
Using(new Source(...)) for Scala 2.11 #582
Comments
sounds like something we'd plausibly merge. want to take a shot at a PR? |
Some code can be inserted at scala-collection-compat/compat/src/main/scala-2.11_2.12/scala/util/Using.scala Lines 395 to 401 in 37d2d5c
object Releasable {
/** An implicit `Releasable` for [[java.lang.AutoCloseable `AutoCloseable`s]]. */
implicit object AutoCloseableIsReleasable extends Releasable[AutoCloseable] {
def release(resource: AutoCloseable): Unit = resource.close()
}
/** An implicit `Releasable` for [[scala.io.Source `Source`s]] which aren't [[java.lang.AutoCloseable `AutoCloseable`s]] in Scala 2.11. */
implicit object SourceReleasable extends Releasable[Source] {
def release(resource: Source): Unit = resource.close()
}
} However, that causes problems for Scala 2.12 because the conversion is then ambiguous. I do not know how to make the Scala 2.11 and 2.12 versions different without duplicating most of the code from the scala-2.11_2.12 directory and putting copies in scala-2.11 and scala-2.12. Other people probably do know how to do this. My test case was import scala.io.Source
...
@Test
def usingSource(): Unit = {
Using(Source.fromString("Hello, Source!")) { source =>
// If this simply compiles, then mission accomplished.
}
} |
I could easily be missing something, but we do have |
See #587. It's more code duplication than I'd like to have, but I know of no better way. Code is copied and pasted between scala-2.11 and scala-2.12. |
In Scala 2.11, Source is not Closeable so that Using(new Source(...)) results in
This can be worked around with code like
If I add that somewhere, I believe that an additional import will be needed in my code. If it gets added somewhere inside scala.util.Using, which seems to be part of this project, the extra import might not be necessary and that would be very nice to have.
The text was updated successfully, but these errors were encountered: