Skip to content

ClassTag inference fails with method call chain #23526

Open
@lrytz

Description

@lrytz
//> 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().

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions