Skip to content

Commit 2523778

Browse files
committed
[Runtime] Add a test for +class and +self overrides.
rdar://problem/49853091
1 parent 0c1fa5f commit 2523778

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <Foundation/Foundation.h>
2+
3+
// A class that overrides +class and +self to return nil.
4+
@interface EvilClass: NSObject
5+
@end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import "EvilClass.h"
2+
3+
@implementation EvilClass
4+
5+
+ (Class)class { return nil; }
6+
+ (id)self { return nil; }
7+
8+
@end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module EvilClass {
2+
header "EvilClass.h"
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-clang -fobjc-arc %S/Inputs/ObjCEvilClassInitialization/EvilClass.m -c -o %t/EvilClass.o
3+
// RUN: %target-build-swift -I %S/Inputs/ObjCEvilClassInitialization/ %t/EvilClass.o %s -o %t/a.out
4+
// RUN: %target-codesign %t/a.out
5+
// RUN: %target-run %t/a.out
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: objc_interop
9+
10+
import EvilClass
11+
12+
import StdlibUnittest
13+
14+
let tests = TestSuite("ObjCEvilClassInitialization")
15+
16+
tests.test("GenericOnEvilClass") {
17+
struct Generic<T> {
18+
var type: T.Type { return T.self }
19+
}
20+
let g = Generic<EvilClass>()
21+
expectEqual("\(type(of: g))", "Generic<EvilClass>")
22+
expectEqual(g.type, EvilClass.self)
23+
}
24+
25+
runAllTests()

0 commit comments

Comments
 (0)