Open
Description
//> using scala 3.7.1
trait B[-A, +To] {
def addOne(e: A): this.type = this
def res(): To
}
class Col[A]
object Factory {
def newB[A: reflect.ClassTag] = new B[A, Col[A]] { def res(): Col[A] = new Col[A] }
}
def t = Factory.newB.addOne(1).res()
gives
[error] ./A.scala:15:21
[error] No ClassTag available for A
[error]
[error] where: A is a type variable
[error] def t = Factory.newB.addOne(1).res()
[error] ^
It works for a non-ClassTag evidence, e.g., when changing A: reflect.ClassTag
to A: Numeric
.
Example using collections: collection.immutable.ArraySeq.newBuilder.addOne(1).result()
.