Skip to content

Commit

Permalink
Re-lub also hard union types in simplify (#20027)
Browse files Browse the repository at this point in the history
Simplify had some elaborate condition that prevented hard union types to
be recomputed with a lub. I am not sure why that was. In the concrete
scenario of i10693.scala, we had an explicitly written union result type
`B | A` where `A` and `B` are type parameters. So that is a hard union
type. Then `A` was instantiated to `Int | String` and `B` was
instantiated to `String | Int`. Re-forming the lub of that union would
have eliminated one pair, but since the union type was hard that was not
done. On the other hand I see no reason why hard unions should not be
re-lubbed. Hard unions are about preventing the widening of or types
with a join. I don't see a connection with avoiding re-lubbing.

Fixes #10693
  • Loading branch information
smarter committed Apr 4, 2024
2 parents 6e17c0e + 5a15892 commit fd2a03e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions compiler/test-resources/repl/10693
@@ -0,0 +1,16 @@
scala> def test[A, B](a: A, b: B): A | B = a
def test[A, B](a: A, b: B): A | B
scala> def d0 = test("string", 1)
def d0: String | Int
scala> def d1 = test(1, "string")
def d1: Int | String
scala> def d2 = test(d0, d1)
def d2: String | Int
scala> def d3 = test(d1, d0)
def d3: Int | String
scala> def d4 = test(d2, d3)
def d4: String | Int
scala> def d5 = test(d3, d2)
def d5: Int | String
scala> def d6 = test(d4, d5)
def d6: String | Int

0 comments on commit fd2a03e

Please sign in to comment.