Skip to content

type resolution with path-dependent types fails (works in Scala 2) #22210

Closed as not planned
@yurique

Description

@yurique

Compiler version

3.3.4, 3.6.2

Minimized code

trait Module {
  trait Reader[T]
}

class Builder[M <: Module](val m: M) {

  def json[Receive](implicit
                    reader: m.Reader[Receive], // path-dependent type here
                   ): Unit = {}

}

object mod extends Module

object Main {

  implicit val stringReader: mod.Reader[String] = new mod.Reader[String] {}

  def builder[M <: Module](m: M): Builder[M] = new Builder[M](m)

  def main(args: Array[String]): Unit = {
    builder(mod).json[String](stringReader) // the expected type of the reader parameter is Nothing  
   
  }

}

Output

$ scala-cli --scala 3.6.2 test.sc
Compiling project (Scala 3.6.2, JVM (17))
[error] ./test.sc:22:31
[error] Found:    (test$_.Main.stringReader : test$_.this.mod.Reader[String])
[error] Required: Nothing
[error]     builder(mod).json[String](stringReader) // the expected type of the reader parameter is Nothing
[error]                               ^^^^^^^^^^^^
Error compiling project (Scala 3.6.2, JVM (17))
Compilation failed
$ scala-cli --scala 2.13.15 test.sc
Compiling project (Scala 2.13.15, JVM (17))
Compiled project (Scala 2.13.15, JVM (17))

Expectation

I was expecting this to compile in Scala 3, since it compiles and works in Scala 2.13.
But I don't know if this is supposed to work, or if I'm doing it wrong, or if there is a workaround.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions