Skip to content

Conversation

@jchyb
Copy link
Contributor

@jchyb jchyb commented Oct 13, 2025

Fixes #24038

In the minimisation, the typer phase expanded

case abcd: (h *: t, bh *: bt) =>
      val (hh *: tt, bh *: bt) = abcd

into

case abcd @ _:Tuple2[*:[h @ _, t @ _], *:[bh @ _, bt @ _]] =>
  val $1$: (Any, Tuple, Any, Tuple) =
    abcd:((T, M[T]) & (h *: t, bh *: bt)) @unchecked match 
      {
        case 
          Tuple2.unapply[T, M[T]](
            *:.unapply[Any, Tuple](hh @ _, tt @ _):(Any *: Tuple),
            *:.unapply[Any, Tuple](bh @ _, bt @ _):(Any *: Tuple))
            => Tuple4.apply[Any, Tuple, Any, Tuple](hh, tt, bh, bt)
      }
  val hh: Any = $1$._1
  val tt: Tuple = $1$._2
  val bh: Any = $1$._3
  val bt: Tuple = $1$._4

Before the change in #23923 it would simplify ((T, M[T]) & (h *: t, bh *: bt)) into (T & (h *: t), M[T] & (bh *: bt)) and thus generate:

case abcd @ _:Tuple2[*:[h @ _, t @ _], *:[bh @ _, bt @ _]] =>
  val $1$: (h, t, bh, bt) =
    abcd:(T & h *: t, M[T] & bh *: bt) @unchecked match 
      {
        case 
          Tuple2.unapply[T & h *: t, M[T] & bh *: bt](
            *:.unapply[h, t](hh @ _, tt @ _),
            *:.unapply[bh, bt](bh @ _, bt @ _))
          => Tuple4.apply[h, t, bh, bt](hh, tt, bh, bt)
      }
  val hh: h = $1$._1
  val tt: t = $1$._2
  val bh: bh = $1$._3
  val bt: bt = $1$._4

Since it looks like this simplification is now illegal, and the unapply generation for intersection types seems to prioritize the leftmost argument, to fix this we make sure that when typing Binds we prioritize the user-created tree.tpe and deprioritize the inferred proto type, which hopefully is enough.

@jchyb jchyb force-pushed the fix-i24038-intersection-distribution-regression branch from 72fcb5b to 8dd34d2 Compare October 19, 2025 13:30
@jchyb jchyb force-pushed the fix-i24038-intersection-distribution-regression branch from 8dd34d2 to 901744a Compare October 26, 2025 11:38
@jchyb jchyb marked this pull request as ready for review October 26, 2025 17:39
@jchyb jchyb requested a review from EugeneFlesselle October 27, 2025 10:33
@Gedochao Gedochao requested a review from odersky October 29, 2025 16:02
@Gedochao Gedochao assigned odersky and unassigned EugeneFlesselle Oct 29, 2025
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice analysis leading to super-simple fix.

@odersky odersky merged commit 714f3b6 into scala:main Nov 2, 2025
51 checks passed
@odersky odersky deleted the fix-i24038-intersection-distribution-regression branch November 2, 2025 17:58
@WojciechMazur WojciechMazur added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Nov 11, 2025
@WojciechMazur WojciechMazur added this to the 3.8.0 milestone Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in pityka/relational3 for transparent inline with match types

4 participants