scala3
scala3 copied to clipboard
Union of Function0 creates an intersection of return type (regression from 3.1.1?)
Compiler version
3.1.3
Minimized code
object EB:
type Outcome = Command | SideEffect | CmdEffect
type OutcomeSpec = Command | (() => Unit) | (() => Seq[Command])
inline def asOutcome(o: OutcomeSpec): Outcome =
inline o match
case c: Command => c
case f: (() => Seq[Command]) => CmdEffect(_ => f())
case f: (() => Unit) => SideEffect(_ => f())
inline def apply[S](ev: WithSource[Event, S], ctx: String, f: OutcomeSpec): EB[S] =
...
EB(b.st.release, "", () => Seq.empty[Command])
Output
Found: Seq[Command]
Required: Unit & Seq[Command]
Expectation
In 3.1.1 this compiled fine, not sure if this is a regression or the rules changed.
Minimized to:
sealed trait Command
object EB:
type OutcomeSpec = (() => Unit) | (() => Seq[Command])
inline def apply(f: OutcomeSpec) = ???
def usage = EB(() => Seq.empty[Command])
Bisect points to https://github.com/lampepfl/dotty/commit/40ae7eee109a3c8a3a125c1ec4a2167bba2acd9c
For me this compiles with both current main and 3.2.1-RC1-bin-20220805-e560c2d-NIGHTLY.
The bug is present also in 3.2.0-RC3 so it must have been fixed recently. I think it is a good idea to find the commit with the fix and think about backporting it to 3.2.0-RC4.
Since it works and was not backported I think we can close now.
I have just upgraded to 3.2.0 and the bug is still present. Will wait till 3.2.1 I guess.
Will wait till 3.2.1 I guess
try 3.2.1-RC1, which is now out