Closed hmemcpy closed 1 year ago
This is zio 1.0.17. It's helpful to provide a minimal build (or scala-cli header). The example needs an import Server.Pizza
to compile.
Dotty says
[error] -- [E007] Type Mismatch Error: .../t12707/src/main/scala/t12707.scala:13:23
[error] 13 | handler("blah", 1).unit
[error] | ^^^^^^^^^^^^^^^^^^^^^^^
[error] | Found: zio.ZIO[zio.console.Console & Server.Pizza, Nothing, Unit]
[error] | Required: zio.ZIO[zio.console.Console & Server.Broccoli, Nothing, Unit]
[error] |
[error] | longer explanation available when compiling with `-explain`
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 6 s, completed Jan 1, 2023, 10:50:35 AM
If it is agreed that this is correct behavior, then -Xsource:3
is doing the right thing, which is to show what will happen under migration. (Matching Dotty behavior is best-effort.)
The type inferred from RHS was type C0 = zio.ZIO[zio.console.Console, Nothing, String]
.
The reason to prefer to infer the overridden type was that the RHS (as a co-variant subtype) is too constraining, such as an Option[_]
narrowed to None
. But perhaps inference should be more loosey-goosey with contravariant type params. As in the example, the RHS expresses a subtype that is less constrained in that type param. (But consider further overriding.)
Further questions about contravariance and override: https://github.com/lampepfl/dotty/issues/10079
a meta-issue here is that we don't have good documentation for -Xsource
: https://github.com/scala/scala-dev/issues/470
For anyone happening to land on this ticket, note that as of 2.13.13 the behavior change with inferred return types on overrides no longer occurs under -Xsource:3
, only under the new -Xsource:3-cross
.
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:Causing the following mismatch:
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.