Skip to content

Commit 6015361

Browse files
committed
Expand pattern match position tests.
- Adds tests for unapplySeq and unapply: Boolean. Both seem to be well positioned after the previous changes.
1 parent 286dced commit 6015361

File tree

2 files changed

+82
-11
lines changed

2 files changed

+82
-11
lines changed

test/files/run/t6288.check

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[[syntax trees at end of patmat]] // newSource1
22
[7]package [7]<empty> {
3-
[7]object Case3 extends [13][105]scala.AnyRef {
4-
[105]def <init>(): [13]Case3.type = [105]{
5-
[105][105][105]Case3.super.<init>();
3+
[7]object Case3 extends [13][106]scala.AnyRef {
4+
[106]def <init>(): [13]Case3.type = [106]{
5+
[106][106][106]Case3.super.<init>();
66
[13]()
77
};
88
[21]def unapply([29]z: [32]<type: [32]scala.Any>): [21]Option[Int] = [56][52][52]scala.Some.apply[[52]Int]([58]-1);
@@ -25,6 +25,61 @@
2525
[64]x
2626
}
2727
}
28+
};
29+
[113]object Case4 extends [119][217]scala.AnyRef {
30+
[217]def <init>(): [119]Case4.type = [217]{
31+
[217][217][217]Case4.super.<init>();
32+
[119]()
33+
};
34+
[127]def unapplySeq([138]z: [141]<type: [141]scala.Any>): [127]Option[List[Int]] = [167]scala.None;
35+
[175]{
36+
[175]case <synthetic> val x1: [175]Any = [175]"";
37+
[175]case5()[195]{
38+
[195]<synthetic> val o7: [195]Option[List[Int]] = [195][195]Case4.unapplySeq([195]x1);
39+
[195]if ([195]o7.isEmpty.unary_!)
40+
[195]if ([195][195][195][195]o7.get.!=([195]null).&&([195][195][195][195]o7.get.lengthCompare([195]1).==([195]0)))
41+
[195]{
42+
[201]val nr: [201]Int = [201][201]o7.get.apply([201]0);
43+
[208][208]matchEnd4([208]())
44+
}
45+
else
46+
[195][195]case6()
47+
else
48+
[195][195]case6()
49+
};
50+
[175]case6(){
51+
[175][175]matchEnd4([175]throw [175][175][175]new [175]MatchError([175]x1))
52+
};
53+
[175]matchEnd4(x: [NoPosition]Unit){
54+
[175]x
55+
}
56+
}
57+
};
58+
[224]object Case5 extends [230][312]scala.AnyRef {
59+
[312]def <init>(): [230]Case5.type = [312]{
60+
[312][312][312]Case5.super.<init>();
61+
[230]()
62+
};
63+
[238]def unapply([246]z: [249]<type: [249]scala.Any>): [238]Boolean = [265]true;
64+
[273]{
65+
[273]case <synthetic> val x1: [273]Any = [273]"";
66+
[273]case5()[293]{
67+
[293]<synthetic> val o7: [293]Option[List[Int]] = [293][293]Case4.unapplySeq([293]x1);
68+
[293]if ([293]o7.isEmpty.unary_!)
69+
[293]if ([293][293][293][293]o7.get.!=([293]null).&&([293][293][293][293]o7.get.lengthCompare([293]0).==([195]0)))
70+
[304][304]matchEnd4([304]())
71+
else
72+
[293][293]case6()
73+
else
74+
[293][293]case6()
75+
};
76+
[273]case6(){
77+
[273][273]matchEnd4([273]throw [273][273][273]new [273]MatchError([273]x1))
78+
};
79+
[273]matchEnd4(x: [NoPosition]Unit){
80+
[273]x
81+
}
82+
}
2883
}
2984
}
3085

test/files/run/t6288.scala

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,30 @@ object Test extends DirectTest {
66
override def extraSettings: String = "-usejavacp -Xprint:patmat -Xprint-pos -d " + testOutput.path
77

88
override def code =
9-
"""
10-
|object Case3 {
11-
| def unapply(z: Any): Option[Int] = Some(-1)
12-
|
13-
| "" match {
14-
| case Case3(nr) => ()
15-
| }
16-
|}""".stripMargin.trim
9+
"""
10+
|object Case3 {
11+
| def unapply(z: Any): Option[Int] = Some(-1)
12+
|
13+
| "" match {
14+
| case Case3(nr) => ()
15+
| }
16+
|}
17+
|object Case4 {
18+
| def unapplySeq(z: Any): Option[List[Int]] = None
19+
|
20+
| "" match {
21+
| case Case4(nr) => ()
22+
| }
23+
|}
24+
|object Case5 {
25+
| def unapply(z: Any): Boolean = true
26+
|
27+
| "" match {
28+
| case Case4() => ()
29+
| }
30+
|}
31+
|
32+
|""".stripMargin.trim
1733

1834
override def show(): Unit = {
1935
// Now: [84][84]Case3.unapply([84]x1);

0 commit comments

Comments
 (0)