Skip to content

Type mismatch under -Xsource:3 with inferred overridden types #12707

Closed as not planned
@hmemcpy

Description

@hmemcpy

Reproduction steps

A recent change in Scala 2.13.9 (#9891) caused a lot of compilation errors in our code base that was previously compiling. We're using ZIO, and heavily rely on type inference, so most of our codebase omits type signatures. The following snippet is compiles fine in Scala 2.13 with -Xsource:3 before 2.13.9:

import zio.*
import zio.console.Console

object Server {
  type Pizza
  type Broccoli
  
  val start: ZIO[Console & Broccoli, Nothing, Unit] = {
    val handler = (ServiceImpl.foo _).tupled
    handler("blah", 1).unit
  }
}

trait Service[-R] {
  def foo(s: String, i: Int): ZIO[R, Nothing, String]
}

object ServiceImpl extends Service[Console & Pizza]{
  def foo(s: String, i: Int) =
    zio.console.putStrLn("blah").orDie.as("")
}

Causing the following mismatch:

type mismatch;
 found   : zio.ZIO[zio.console.Console with Server.Pizza,Nothing,Unit]
    (which expands to)  zio.ZIO[zio.Has[zio.console.Console.Service] with Server.Pizza,Nothing,Unit]
 required: zio.ZIO[zio.console.Console with Server.Broccoli,Nothing,Unit]
    (which expands to)  zio.ZIO[zio.Has[zio.console.Console.Service] with Server.Broccoli,Nothing,Unit]
    handler("blah", 1).unit

I understand the nature of the change, but I would like a workaround that does not require me to change hundreds of type signatures... Please advise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions