Skip to content

Code does not compile when using T as v instead of using v: T #23272

Open
@OndrejSpanel

Description

@OndrejSpanel

Compiler version

3.6.0, 3.7.0, 3.7.1-RC2

Minimized code

//> using scala 3.7.0

trait Vectoric[V] {
  def components: Array[V => Double]
  def map(a: V)(f: Double => Double): V
}

trait VectoricOps {
  extension [V: Vectoric as v](lhs: V) {
    def map(f: Double => Double): V = v.map(lhs)(f)
    def toArray: Array[Double] = v.components.map(c => c(lhs))
  }
}

Output

[error] .\Main.scala:11:56
[error] parameter c does not take parameters
[error]     def toArray: Array[Double] = v.components.map(c => c(lhs))
[error]                                                        ^
[error] .\Main.scala:11:63
[error] No given instance of type Vectoric[Array[V => Double]] was found for parameter v of method map in trait VectoricOps
[error]     def toArray: Array[Double] = v.components.map(c => c(lhs))
[error]

Expectation

The code should compile. The same code compiles when using extension [V](lhs: V)(using v: Vectoric[V])

Maybe my expectation is wrong and the two forms are not equivalent, in which can I would be glad if anyone can explain the difference.

Note

There is no error when I remove the map method from VectoricOps extension.

The same error is produced when using:

  extension [V: Vectoric](lhs: V) {
    def map(f: Double => Double): V = ???
    def toArray: Array[Double] = summon[Vectoric[V]].components.map(c => c(lhs))
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions