scala-newtype
scala-newtype copied to clipboard
Stop @newtype to warn for implicit conversions
If you neither set the '-language:implicitConversions' flag, nor the 'import scala.language.implicitConversions', the '@newtype' construct warns for implicit conversions.
I've tried, and this PR prevents it.
This is the reopening of this PR (given the other had problems with the travis-ci cache): https://github.com/estatico/scala-newtype/pull/62
@kailuowang No, not really
In fact, if you add your own custom code to the companion object, and your code has implicit conversions, that custom code will behave as expected.
That is, if you neither have the import nor the compiler flag, it will trigger the corresponding warning. It will do nothing otherwise.
Sorry I am still on paternity leave. What I would like to test is if having delicate import trigger an unused import warning.
Hi @kailuowang , thanks for the feedback. After your comment, I've run a battery of tests and made some corrections to the PR out of the results.
All the experiments I've run with the following compiler flags:
scalacOptions ++= Seq(
"-feature",
"-Ywarn-unused:imports" // on scala 2.12 and 2.13
// "-Ywarn-unused-import" // on scala 2.11
)
I've run all the experiments with two versions of a very simple main file:
version 1 (case class):
import io.estatico.newtype.macros.newtype
object Main extends App {
@newtype case class Foo(i: Int)
println("Hello, World!")
}
version 2 (normal class):
import io.estatico.newtype.macros.newtype
object Main extends App {
@newtype class Foo(i: Int)
println("Hello, World!")
}
I tried to compile the two versions with scala 2.11.12, 2.12.11 and 2.13.1. Both with the current version of newtype and with the one inside this PR.
Note: HK means warning about missing the higherKinded language flag. IC means warning about missing the implicitConversions language flag.
Currently
case class | class
2.11 HK x 3, IC x 1 | HK x 3
2.12 HK x 3, IC x 1 | HK x 3
2.13 IC x 1 | -
PR
case class | class
2.11 - | _
2.12 - | _
2.13 - | _