Skip to content

Type inference failure(Required: Nothing) #12909

Closed
@xuwei-k

Description

@xuwei-k

Compiler version

3.0.0, 3.0.1-RC2 and 3.0.2-RC1-bin-20210622-a059dbc-NIGHTLY

Minimized code

package example

final case class Writer[W, A](run: (W, A)) {
  def map[B](f: A => B): Writer[W, B] = ???

  def flatMap[B](f: A => Writer[W, B]): Writer[W, B] = ???
}

object Main {
  implicit class WriterOps[A](a: A) {
    def set[W](w: W): Writer[W, A] = ???
  }

  def x1[A]: Writer[Vector[String], Option[A]] = ???

  val failure = for {
    a1 <- {
      Option(1) match {
        case Some(x) =>
          x1[Boolean]
        case _ =>
          Option.empty[Boolean].set(Vector.empty[String])
      }
    }
    a2 <- x1[String]
  } yield ()


  val success = for {
    a1 <- {
      val temp = Option(1) match {
        case Some(x) =>
          x1[Boolean]
        case _ =>
          Option.empty[Boolean].set(Vector.empty[String])
      }
      // why ???
      temp
    }
    a2 <- x1[String]
  } yield ()

}

Output

[error] -- [E007] Type Mismatch Error: /Users/kenji/writer-scala-3/Writer.scala:25:4 -----
[error] 25 |    a2 <- x1[String]
[error]    |    ^
[error]    |    Found:    example.Writer[Vector[String], Unit]
[error]    |    Required: Nothing
[error] 26 |  } yield ()
[error] one error found

Expectation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions