Skip to content

Commit fee148f

Browse files
committed
Fix-#4867 Update union tests to improve inference when ascribed
Splits union.scala test from negative to negative and positive tests, exhibiting the preservation of the union when the union has been explicitly ascribed as per fix #4867.
1 parent 4b11b33 commit fee148f

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

tests/neg/union.scala

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,14 @@ object Test {
33
class A
44
class B extends A
55
class C extends A
6-
class D extends A
76

87
val b = true
9-
val x = if (b) new B else new C
10-
val y: B | C = x // error
11-
}
12-
13-
object O {
14-
class A
15-
class B
16-
def f[T](x: T, y: T): T = x
17-
18-
val x: A = f(new A { }, new A)
19-
20-
val y1: A | B = f(new A { }, new B) // error
21-
val y2: A | B = f[A | B](new A { }, new B) // ok
228

23-
val z = if (???) new A{} else new B
9+
val x: B | C = if (b) new B else new C
2410

25-
val z1: A | B = z // error
11+
val y: B | C = x
12+
val ok: B | C = y // ok, as x and y are ascribed with unions
2613

27-
val z2: A | B = if (???) new A else new B // ok
14+
val z = x
15+
val error: B | C = z // error, as z is not ascribed with an union
2816
}

tests/pos/union.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
object Test {
2+
3+
class A
4+
class B extends A
5+
class C extends A
6+
class D extends A
7+
8+
val b = true
9+
val x: B | C = if (b) new B else new C
10+
val y: B | C = x
11+
}
12+
13+
object O {
14+
class A
15+
class B
16+
def f[T](x: T, y: T): T = x
17+
18+
val x: A = f(new A { }, new A)
19+
20+
val y1: A | B = f(new A { }, new B)
21+
val y2: A | B = f[A | B](new A { }, new B)
22+
23+
val z: A | B = if (???) new A{} else new B
24+
25+
val z1: A | B = z
26+
val z2: A | B = if (???) new A else new B
27+
}

0 commit comments

Comments
 (0)