Skip to content

Commit 4c98f13

Browse files
committed
Add test case for leak fixed by my SILGenPattern work.
The problem here was that we were performing a copy_on_success and then not destroying that copy. We now do destroy that copy on master. This test will make sure that we do not regress. rdar://43076139
1 parent 2123405 commit 4c98f13

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %target-run-simple-swift
2+
3+
// REQUIRES: executable_test
4+
5+
import StdlibUnittest
6+
7+
// Make sure that in the following code we do not leak the case of the enum.
8+
9+
protocol MyProtocol {}
10+
11+
// An enum that wraps LeakingClass
12+
enum LeakingEnum1: MyProtocol {
13+
case eNone1
14+
case eLeakingClass1(LifetimeTracked)
15+
}
16+
17+
// An enum that wraps LeakingClass
18+
enum LeakingEnum2 : MyProtocol {
19+
case eNone2
20+
case eLeakingClass2(LifetimeTracked)
21+
}
22+
23+
var Tests = TestSuite("patternmatch_on_enum_protocol_leak")
24+
25+
Tests.test("dontLeak") {
26+
do {
27+
let leakingClass = LifetimeTracked(0)
28+
let leakEnum = LeakingEnum1.eLeakingClass1(leakingClass)
29+
let control: MyProtocol = leakEnum
30+
31+
// This switch case order, interleaving LeakingEnum1 and LeakingEnum2 cases triggers the leak.
32+
switch control
33+
{
34+
case LeakingEnum1.eNone1: break
35+
case LeakingEnum2.eNone2: break
36+
37+
case LeakingEnum1.eLeakingClass1: break
38+
case LeakingEnum2.eLeakingClass2: break
39+
40+
default: break
41+
}
42+
}
43+
expectEqual(0, LifetimeTracked.instances)
44+
}
45+
46+
runAllTests()

0 commit comments

Comments
 (0)