Skip to content

Unexpected "scrutinee is incompatible with pattern type" in for-comprehension #12656

@DaniRey

Description

@DaniRey

The following code

import zio.prelude.Subtype

object PreludeForComprehensionIssue extends App {
  object ArbitrarySubType extends Subtype[String]
  type ArbitrarySubType = ArbitrarySubType.Type

  val subTypeInstance: ArbitrarySubType = ArbitrarySubType("I am the sub type instance")

  val result = for {
    _ <- Some("A")
    b: ArbitrarySubType <- Some(subTypeInstance)
  } yield b

  println(result)
}

produces the error

scrutinee is incompatible with pattern type;
 found   : PreludeForComprehensionIssue.ArbitrarySubType
    (which expands to)  PreludeForComprehensionIssue.ArbitrarySubType.Type
 required: String

in Scala 2.13.9. It compiles without issues in Scala 3.2.0.
It can also be compiled without issues by adding better-monadic-for https://github.com/oleg-py/better-monadic-for

It can be tried via https://scastie.scala-lang.org/nYj3MNfXQFGE62TaQK7G5A
The only required dependency is "dev.zio" %% "zio-prelude" % "1.0.0-RC16",

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)patmat

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions