According to this question and the scala language spec, it's possible to exclude imports by using the syntax e.g. import java.{xxx => _, _}
.
However, I'm finding that this doesn't work for implicits. For example:
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions for evaluation. Or try :help.
scala> import schema.Encoder.{ofGeneric => _, _}
import schema.Encoder.{ofGeneric=>_, _}
As per the spec, the member is not accessible:
scala> ofGeneric
<console>:15: error: not found: value ofGeneric
ofGeneric
^
However, it is in implicit scope, and I can access it implicitly:
scala> :implicits
/* 10 implicit members imported from schema.Encoder */
/* 10 defined in schema.Encoder */
implicit val ofBoolean: Boolean]
implicit def ofConcreteElem[K <: Symbol, A](implicit witness: shapeless.Witness.Aux[K],i
mplicit E: A]): shapeless.labelled.FieldType[K,A]]
implicit val ofDateTime: java.time.OffsetDateTime]
implicit val ofDouble: Double]
implicit def ofElem[K <: Symbol, A, C[_]](implicit witness: shapeless.Witness.Aux[K],imp
licit E: shapeless.Lazy[A]],implicit C: cats.Foldable[C]): shapeless.labelled.FieldType[K,
C[A]]]
implicit def ofGeneric[A, L <: shapeless.HList](implicit G: shapeless.LabelledGeneric.Au
x[A,L],implicit HE: shapeless.Lazy[L]]): A]
implicit def ofHListSeq[K <: Symbol, H, T <: shapeless.HList](implicit witness: shapeles
s.Witness.Aux[K],implicit HE: shapeless.Lazy[shapeless.labelled.FieldType[K,H]]],implicit
TE: shapeless.Lazy[T]]): shapeless.labelled.FieldType[K,H] :: T]
implicit val ofHNil: shapeless.HNil]
implicit val ofInt: Int]
implicit def ofString: String]
scala> implicitly[schema.Encoder[Tuple2[Int,String]]]
res3: schema.Encoder[(Int, String)] = schema.Encoder$$anonfun$ofGeneric$2@341619cc
^^^^^^^^^
Questions:
- Is this a bug in the console, or a language feature?
- Is there any way to get around this (i.e. import all implicit members except one), without specifying each function individually?