Skip to content

Commit 959ab41

Browse files
committed
Simplify mixin forwarders tests
Now that -Xmixin-force-forwarders defaults to true, tests that showcase some behavior of mixin forwarders can be simplified since we need less indirections to generate them.
1 parent 80eb343 commit 959ab41

File tree

8 files changed

+38
-73
lines changed

8 files changed

+38
-73
lines changed
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<527..527> in mixin-forwarder-clash1.scala
1+
<284..284> in mixin-forwarder-clash1.scala
22
Name clash between inherited members:
3-
override def concat(suffix: Int): X in trait OneB at line 10 and
4-
override def concat: [Dummy](suffix: Int): Y in trait TwoB at line 18
3+
def concat(suffix: Int): X in trait One at line 4 and
4+
def concat: [Dummy](suffix: Int): Y in trait Two at line 8
55
have the same type after erasure.
+10-20
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
class Foo
22

3-
// Using self-types to force mixin forwarders
4-
5-
trait OneA[X] {
3+
trait One[X] {
64
def concat(suffix: Int): X = ???
75
}
86

9-
trait OneB[X] { self: OneA[X] =>
10-
override def concat(suffix: Int): X = ???
11-
}
12-
13-
trait TwoA[Y/* <: Foo*/] {
7+
trait Two[Y/* <: Foo*/] {
148
def concat[Dummy](suffix: Int): Y = ???
159
}
1610

17-
trait TwoB[Y/* <: Foo*/] { self: TwoA[Y] =>
18-
override def concat[Dummy](suffix: Int): Y = ???
19-
}
20-
21-
class Bar1 extends OneA[Foo] with OneB[Foo]
11+
class Bar1 extends One[Foo]
2212
// Because mixin forwarders are generated after erasure, we get:
2313
// override def concat(suffix: Int): Object
2414

25-
class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error
26-
// We get a mixin forwarder for TwoB:
15+
class Bar2 extends Bar1 with Two[Foo] // error
16+
// We get a mixin forwarder for Two:
2717
// override def concat(suffix: Int): Object
2818
// This clashes with the forwarder generated in Bar1, and the compiler detects that:
2919
//
30-
// |class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo]
20+
// |class Bar2 extends Bar1 with Two[Foo]
3121
// | ^
32-
// | Name clash between inherited members:
33-
// | override def concat(suffix: Int): Object in trait OneB at line 10 and
34-
// | override def concat: [Dummy](suffix: Int): Y in trait TwoB at line 18
35-
// | have the same type after erasure.
22+
// | Name clash between inherited members:
23+
// | def concat(suffix: Int): X in trait One at line 4 and
24+
// | def concat: [Dummy](suffix: Int): Y in trait Two at line 8
25+
// | have the same type after erasure.
3626
//
3727
// This also works with separate compilation as demonstrated by
3828
// mixin-forwarder-clash2.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<6..6> in B_2.scala
22
Name clash between inherited members:
3-
override def concat(suffix: Int): X in trait OneB and
4-
override def concat: [Dummy](suffix: Int): Y in trait TwoB
3+
def concat(suffix: Int): X in trait One and
4+
def concat: [Dummy](suffix: Int): Y in trait Two
55
have the same type after erasure.
+3-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
class Foo
22

3-
// Using self-types to force mixin forwarders
4-
5-
trait OneA[X] {
3+
trait One[X] {
64
def concat(suffix: Int): X = ???
75
}
86

9-
trait OneB[X] { self: OneA[X] =>
10-
override def concat(suffix: Int): X = ???
11-
}
12-
13-
trait TwoA[Y/* <: Foo*/] {
7+
trait Two[Y/* <: Foo*/] {
148
def concat[Dummy](suffix: Int): Y = ???
159
}
1610

17-
trait TwoB[Y/* <: Foo*/] { self: TwoA[Y] =>
18-
override def concat[Dummy](suffix: Int): Y = ???
19-
}
20-
21-
class Bar1 extends OneA[Foo] with OneB[Foo]
11+
class Bar1 extends One[Foo]
2212
// Because mixin forwarders are generated after erasure, we get:
2313
// override def concat(suffix: Int): Object
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error
2-
// We get a mixin forwarder for TwoB:
1+
class Bar2 extends Bar1 with Two[Foo] // error
2+
// We get a mixin forwarder for Two:
33
// override def concat(suffix: Int): Object
44
// This clashes with the forwarder generated in Bar1, and
55
// we can detect that even with separate compilation,
@@ -11,6 +11,6 @@ class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error
1111
// |class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo]
1212
// | ^
1313
// | Name clash between inherited members:
14-
// | override def concat(suffix: Int): X in trait OneB and
15-
// | override def concat: [Dummy](suffix: Int): Y in trait TwoB
14+
// | def concat(suffix: Int): X in trait One and
15+
// | def concat: [Dummy](suffix: Int): Y in trait Two
1616
// | have the same type after erasure.

tests/pos/mixin-forwarder-clash1.scala

+6-16
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,26 @@
44

55
class Foo
66

7-
// Using self-types to force mixin forwarders
8-
9-
trait OneA[X] {
7+
trait One[X] {
108
def concat(suffix: Int): X = ???
119
}
1210

13-
trait OneB[X] { self: OneA[X] =>
14-
override def concat(suffix: Int): X = ???
15-
}
16-
17-
trait TwoA[Y <: Foo] {
11+
trait Two[Y <: Foo] {
1812
def concat[Dummy](suffix: Int): Y = ???
1913
}
2014

21-
trait TwoB[Y <: Foo] { self: TwoA[Y] =>
22-
override def concat[Dummy](suffix: Int): Y = ???
23-
}
24-
25-
class Bar1 extends OneA[Foo] with OneB[Foo]
15+
class Bar1 extends One[Foo]
2616
// Because mixin forwarders are generated before erasure, we get:
2717
// override def concat(suffix: Int): Foo
2818

29-
class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error
30-
// We get a mixin forwarder for TwoB:
19+
class Bar2 extends Bar1 with Two[Foo] // error
20+
// We get a mixin forwarder for Two:
3121
// override def concat[Dummy](suffix: Int): Foo
3222
// which gets erased to:
3323
// override def concat(suffix: Int): Foo
3424
// This clashes with the forwarder generated in Bar1, and the compiler detects that:
3525
//
36-
// |class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo]
26+
// |class Bar2 extends Bar1 with Two[Foo]
3727
// | ^
3828
// | Name clash between defined and inherited member:
3929
// | override def concat(suffix: Int): Foo in class Bar1 and
+8-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
class Foo
1+
// This test case was supposed to fail when mixin forwarders were generated before erasure,
2+
// but didn't due to separate compilation unlike mixin-forwarder-clash1,
3+
// it's not supposed to fail anymore since the forwarders generated after erasure do not clash,
4+
// the comments are preserved for posterity.
25

3-
// Using self-types to force mixin forwarders
6+
class Foo
47

5-
trait OneA[X] {
8+
trait One[X] {
69
def concat(suffix: Int): X = ???
710
}
811

9-
trait OneB[X] { self: OneA[X] =>
10-
override def concat(suffix: Int): X = ???
11-
}
12-
13-
trait TwoA[Y <: Foo] {
12+
trait Two[Y <: Foo] {
1413
def concat[Dummy](suffix: Int): Y = ???
1514
}
1615

17-
trait TwoB[Y <: Foo] { self: TwoA[Y] =>
18-
override def concat[Dummy](suffix: Int): Y = ???
19-
}
20-
21-
class Bar1 extends OneA[Foo] with OneB[Foo]
16+
class Bar1 extends One[Foo]
2217
// Because mixin forwarders are generated before erasure, we get:
2318
// override def concat(suffix: Int): Foo

tests/pos/mixin-forwarder-clash2/B_2.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// it's not supposed to fail anymore since the forwarders generated after erasure do not clash,
44
// the comments are preserved for posterity.
55

6-
class Bar2 extends Bar1 with TwoA[Foo] with TwoB[Foo] // error
7-
// We get a mixin forwarder for TwoB:
6+
class Bar2 extends Bar1 with Two[Foo] // error
7+
// We get a mixin forwarder for Two:
88
// override def concat[Dummy](suffix: Int): Foo
99
// which gets erased to:
1010
// override def concat(suffix: Int): Foo

0 commit comments

Comments
 (0)