scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Union of Function0 creates an intersection of return type (regression from 3.1.1?)

Open unthingable opened this issue 3 years ago • 3 comments

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.

unthingable avatar Aug 07 '22 12:08 unthingable

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

WojciechMazur avatar Aug 08 '22 07:08 WojciechMazur

For me this compiles with both current main and 3.2.1-RC1-bin-20220805-e560c2d-NIGHTLY.

KacperFKorban avatar Aug 08 '22 09:08 KacperFKorban

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.

Kordyjan avatar Aug 09 '22 08:08 Kordyjan

Since it works and was not backported I think we can close now.

odersky avatar Sep 06 '22 09:09 odersky

I have just upgraded to 3.2.0 and the bug is still present. Will wait till 3.2.1 I guess.

unthingable avatar Sep 06 '22 09:09 unthingable

Will wait till 3.2.1 I guess

try 3.2.1-RC1, which is now out

SethTisue avatar Sep 06 '22 21:09 SethTisue