简体   繁体   中英

Why does a class body affect implicit resolution?

I've stumbled upon this issue by accident when I was experimenting with abstract classes. The following code:

import shapeless._
class A 
  [tuple <: Product, hlist <: HList]
  (tuple: tuple)
  (implicit tupleGeneric: Generic.Aux[tuple, hlist]) 
{
  private val hlist = tupleGeneric.to(tuple)
  println(hlist)
}
new A((1, 'b')) {}

fails to compile with the following message:

could not find implicit value for parameter tupleGeneric: shapeless.Generic.Aux[(Int, Char),shapeless.::[Int,shapeless.::[Char,shapeless.HNil]]]
new A((1, 'b')) {}
    ^

However, if I simply remove the {} part from new A((1, 'b')) {} , it finds that implicit with no problem.

Is this a Scala bug or am I missing something?

Turns out it is a recognized bug.

https://issues.scala-lang.org/browse/SI-8104

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM