Skip to content

Commit d62095a

Browse files
committed
Test case for const T& in Obj-C++ methods
Add a test case that checks the behaviour introduced during the refactor of `importFunctionParameterList` and `importMethodParamsAndReturnType`. The test checks that both Obj-C++ methods and C++ functions treat `const T&` parameters in the same way.
1 parent 4a59d89 commit d62095a

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#import <Foundation/Foundation.h>
2+
3+
struct OptionsStruct {
4+
int intOption;
5+
float floatOption;
6+
};
7+
8+
@interface OptionsConsumerObjC : NSObject
9+
10+
- (nonnull instancetype)initWithOptions:(const OptionsStruct &)options;
11+
+ (nonnull instancetype)consumerWithOptions:(const OptionsStruct &)options;
12+
+ (int)doThingWithOptions:(const OptionsStruct &)options;
13+
- (float)doOtherThingWithOptions:(const OptionsStruct &)options;
14+
15+
@end
16+
17+
struct OptionsConsumerCxx {
18+
OptionsConsumerCxx(const OptionsStruct &options);
19+
static OptionsConsumerCxx build(const OptionsStruct &options);
20+
static int doThing(const OptionsStruct &options);
21+
float doOtherThing(const OptionsStruct &options);
22+
};

test/Interop/Cxx/objc-correctness/Inputs/module.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ module ProtocolNamingConflict [extern_c] {
22
header "protocol-naming-conflict.h"
33
requires objc
44
}
5+
6+
module ConstRefParameter {
7+
header "const-ref-parameter.h"
8+
requires objc
9+
requires cplusplus
10+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// REQUIRES: objc_interop
2+
3+
import ConstRefParameter
4+
5+
func testFunction() {
6+
let a = OptionsStruct(intOption: 1, floatOption: 2.0)
7+
8+
let objc = OptionsConsumerObjC(options: a)
9+
_ = objc.doOtherThing(withOptions: a)
10+
_ = OptionsConsumerObjC.consumer(withOptions: a)
11+
_ = OptionsConsumerObjC.doThing(withOptions: a)
12+
13+
var cxx = OptionsConsumerCxx(a)
14+
_ = cxx.doOtherThing(a)
15+
_ = OptionsConsumerCxx.build(a)
16+
_ = OptionsConsumerCxx.doThing(a)
17+
}
18+
19+
// RUN: %target-swift-ide-test -print-module -module-to-print=ConstRefParameter -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -enable-objc-interop | %FileCheck -check-prefix=CHECK-IDE-TEST %s
20+
21+
// CHECK-IDE-TEST: class OptionsConsumerObjC
22+
// CHECK-IDE-TEST: init(options: OptionsStruct)
23+
// COM: FIXME: should it be consumer(options:)?
24+
// CHECK-IDE-TEST: class func consumer(withOptions options: OptionsStruct) -> Self
25+
// COM: FIXME: should it be doThing(options:)?
26+
// CHECK-IDE-TEST: class func doThing(withOptions options: OptionsStruct) -> Int32
27+
// COM: FIXME: should it be doOtherThing(options:)?
28+
// CHECK-IDE-TEST: func doOtherThing(withOptions options: OptionsStruct) -> Float
29+
30+
// CHECK-IDE-TEST: struct OptionsConsumerCxx
31+
// CHECK-IDE-TEST: init(_ options: OptionsStruct)
32+
// CHECK-IDE-TEST: static func build(_ options: OptionsStruct) -> OptionsConsumerCxx
33+
// CHECK-IDE-TEST: static func doThing(_ options: OptionsStruct) -> Int32
34+
// CHECK-IDE-TEST: mutating func doOtherThing(_ options: OptionsStruct) -> Float
35+
36+
37+
// RUN: %target-swift-frontend -c -enable-experimental-cxx-interop -enable-objc-interop -I %S/Inputs %s -emit-sil -o - | %FileCheck %s
38+
39+
// COM: FIXME: should it be @in_guaranteed OptionsStruct?
40+
// CHECK: [[FN1:%[0-9]+]] = function_ref @$sSo19OptionsConsumerObjCC7optionsABSo0A6StructV_tcfC : $@convention(method) (OptionsStruct, @thick OptionsConsumerObjC.Type) -> @owned OptionsConsumerObjC
41+
// CHECK-NEXT: apply [[FN1]]
42+
// CHECK-SAME: : $@convention(method) (OptionsStruct, @thick OptionsConsumerObjC.Type) -> @owned OptionsConsumerObjC
43+
44+
// COM: FIXME: should it be @in_guaranteed OptionStruct?
45+
// CHECK: [[FN2:%[0-9]+]] = objc_method %8 : $OptionsConsumerObjC, #OptionsConsumerObjC.doOtherThing!foreign : (OptionsConsumerObjC) -> (OptionsStruct) -> Float, $@convention(objc_method) (@in OptionsStruct, OptionsConsumerObjC) -> Float
46+
// CHECK-NEXT: apply [[FN2]]
47+
// CHECK-SAME: : $@convention(objc_method) (@in OptionsStruct, OptionsConsumerObjC) -> Float
48+
49+
// COM: FIXME: should it be @in_guaranteed OptionStruct?
50+
// CHECK: [[FN3:%[0-9]+]] = objc_method %15 : $@objc_metatype OptionsConsumerObjC.Type, #OptionsConsumerObjC.consumer!foreign : (OptionsConsumerObjC.Type) -> (OptionsStruct) -> @dynamic_self OptionsConsumerObjC, $@convention(objc_method) (@in OptionsStruct, @objc_metatype OptionsConsumerObjC.Type) -> @autoreleased OptionsConsumerObjC
51+
// CHECK-NEXT: apply [[FN3]]
52+
// CHECK-SAME: : $@convention(objc_method) (@in OptionsStruct, @objc_metatype OptionsConsumerObjC.Type) -> @autoreleased OptionsConsumerObjC
53+
54+
// COM: FIXME: should it be @in_guaranteed OptionStruct?
55+
// CHECK: [[FN4:%[0-9]+]] = objc_method %22 : $@objc_metatype OptionsConsumerObjC.Type, #OptionsConsumerObjC.doThing!foreign : (OptionsConsumerObjC.Type) -> (OptionsStruct) -> Int32, $@convention(objc_method) (@in OptionsStruct, @objc_metatype OptionsConsumerObjC.Type) -> Int32
56+
// CHECK-NEXT: apply [[FN4]]
57+
// CHECK-SAME: : $@convention(objc_method) (@in OptionsStruct, @objc_metatype OptionsConsumerObjC.Type) -> Int32
58+
59+
// COM: FIXME: should it be @in_guaranteed OptionStruct?
60+
// CHECK: [[FN5:%[0-9]+]] = function_ref @_ZN18OptionsConsumerCxxC1ERK13OptionsStruct : $@convention(c) (OptionsStruct) -> @out OptionsConsumerCxx
61+
// CHECK-NEXT: apply [[FN5]]
62+
// CHECK-SAME: : $@convention(c) (OptionsStruct) -> @out OptionsConsumerCxx
63+
64+
// COM: FIXME: should it be @in_guaranteed OptionStruct?
65+
// CHECK: [[FN6:%[0-9]+]] = function_ref @_ZN18OptionsConsumerCxx12doOtherThingERK13OptionsStruct : $@convention(cxx_method) (@in OptionsStruct, @inout OptionsConsumerCxx) -> Float
66+
// CHECK-NEXT: apply [[FN6]]
67+
// CHECK-SAME: : $@convention(cxx_method) (@in OptionsStruct, @inout OptionsConsumerCxx) -> Float
68+
69+
// COM: FIXME: should it be @in_guaranteed OptionStruct?
70+
// CHECK: [[FN6:%[0-9]+]] = function_ref @_ZN18OptionsConsumerCxx5buildERK13OptionsStruct : $@convention(c) (@in OptionsStruct) -> OptionsConsumerCxx
71+
// CHECK-NEXT: apply [[FN6]]
72+
// CHECK-SAME: : $@convention(c) (@in OptionsStruct) -> OptionsConsumerCxx
73+
74+
// COM: FIXME: should it be @in_guaranteed OptionStruct?
75+
// CHECK: [[FN7:%[0-9]+]] = function_ref @_ZN18OptionsConsumerCxx7doThingERK13OptionsStruct : $@convention(c) (@in OptionsStruct) -> Int32
76+
// CHECK-NEXT: apply [[FN7]]
77+
// CHECK-SAME: : $@convention(c) (@in OptionsStruct) -> Int32

0 commit comments

Comments
 (0)