File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
test/Interop/Cxx/class/inheritance Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ module Fields {
6
6
header "fields.h"
7
7
}
8
8
9
+ module Polymorphism {
10
+ header "polymorphism.h"
11
+ requires cplusplus
12
+ }
13
+
9
14
module SubTypes {
10
15
header "sub-types.h"
11
16
}
Original file line number Diff line number Diff line change
1
+ #ifndef TEST_INTEROP_CXX_CLASS_INHERITANCE_POLYMORPHISM_H_
2
+ #define TEST_INTEROP_CXX_CLASS_INHERITANCE_POLYMORPHISM_H_
3
+
4
+ class Shape {
5
+ public:
6
+ virtual int NumberOfSides () { return 0 ; }
7
+ };
8
+
9
+ class Rectangle : public Shape {
10
+ public:
11
+ virtual int NumberOfSides () { return 4 ; }
12
+ };
13
+
14
+ // For testing runtime polymorphism.
15
+ Shape* MakeShape () {
16
+ return new Rectangle ();
17
+ }
18
+
19
+ #endif // TEST_INTEROP_CXX_CLASS_INHERITANCE_POLYMORPHISM_H_
20
+
Original file line number Diff line number Diff line change
1
+ // RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop)
2
+ //
3
+ // REQUIRES: executable_test
4
+ //
5
+ // XFAIL: *
6
+
7
+ import Polymorphism
8
+ import StdlibUnittest
9
+
10
+
11
+ var PolymorphismTestSuite = TestSuite ( " Determining if runtime polymorphism works " )
12
+
13
+
14
+ PolymorphismTestSuite . test ( " Call overridden methods with pointer to base type " ) {
15
+ // MakeShape() creates a Rectangle and returns the object as a Shape*.
16
+ let shape = MakeShape ( )
17
+
18
+ // DOES NOT WORK: executes the Shape implementation, not the Rectangle
19
+ // version, and thus fails the comparision (0 != 4)
20
+ // Filed as https://github.com/apple/swift/issues/62354.
21
+ expectEqual ( shape!. pointee. NumberOfSides ( ) , 4 )
22
+ }
23
+
24
+ runAllTests ( )
You can’t perform that action at this time.
0 commit comments