Skip to content

Wildcards should infer bounds #11491

Open
@WellingR

Description

@WellingR

The following code compiles on scala 2.12.8, but it does not compile on scala 2.13.0-RC1

object Example {
  sealed trait DBIOAction[+R, +S <: NoStream, -E <: Effect] {
    def flatMap[R2, S2 <: NoStream, E2 <: Effect](f: R => DBIOAction[R2, S2, E2]): DBIOAction[R2, S2, E with E2] = ???
    def map[R2](f: R => R2): DBIOAction[R2, NoStream, E] = ???
  }

  sealed trait NoStream
  sealed trait Streaming[+T] extends NoStream

  trait Effect
  object Effect {
    trait Write extends Effect
    trait Schema extends Effect
  }

  def createSchema(): DBIOAction[Unit, NoStream, Effect.Schema] = ???
  def writeAction(): DBIOAction[Option[Int], NoStream, Effect.Write] = ???

  def test: DBIOAction[Unit, _, _] = for {
    _ <- createSchema()
    _ <- writeAction()
  } yield ()
}

This fails with the following errors

Error:(22, 22) inferred type arguments [Unit,Any,Nothing] do not conform to method flatMap's type parameter bounds [R2,S2 <: example.Example.NoStream,E2 <: example.Example.Effect]
_ <- createSchema()

Error:(22, 7) type mismatch;
found : Unit => example.Example.DBIOAction[Unit,Any,Nothing]
required: Unit => example.Example.DBIOAction[R2,S2,E2]
_ <- createSchema()

Error:(22, 7) type mismatch;
found : example.Example.DBIOAction[R2,S2,example.Example.Effect.Schema with E2]
required: example.Example.DBIOAction[Unit, _, _]
_ <- createSchema()

Oddly enough the code does compile when changing the body of def test to

  for {
    a <- createSchema()
    b <- writeAction()
  } yield ()

It appears that this somehow changes the inferred types which makes it typecheck again...

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/)regressiontyper

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions