You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Sema] Reject @objc functions with incompatible property wrapper in… (#61189)
* [Sema] Reject `@objc` functions with incompatible property wrapper in params
rdar://99443365
When generating `@objc` functions, the parameters were not checked for property wrapper and instead only the wrapped type was checked for compatibility. Added checks and diagnostics for incompatible property wrappers.
Copy file name to clipboardExpand all lines: test/ClangImporter/objc_parse.swift
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -645,9 +645,12 @@ class NewtypeUser {
645
645
@objcfunc intNewtype(a:MyInt){}
646
646
@objcfunc intNewtypeOptional(a:MyInt?){} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
647
647
@objcfunc intNewtypeArray(a:[MyInt]){} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
648
+
// expected-note@-1 {{Swift structs cannot be represented in Objective-C}}
648
649
@objcfunc intNewtypeDictionary(a:[MyInt:NSObject]){} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
650
+
// expected-note@-1 {{Swift structs cannot be represented in Objective-C}}
649
651
@objcfunc cfNewtype(a:CFNewType){}
650
652
@objcfunc cfNewtypeArray(a:[CFNewType]){} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
653
+
// expected-note@-1 {{Swift structs cannot be represented in Objective-C}}
func foo(@WrapperGenericClass _ ref:Int)throws{} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
32
+
// expected-note@-1 {{classes not annotated with @objc cannot be represented in Objective-C}}
func foo(@WrapperStruct _ ref:Int)throws{} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
55
+
// expected-note@-1 {{Swift structs cannot be represented in Objective-C}}
56
+
}
57
+
58
+
@propertyWrapper
59
+
publicstructWrapperStruct{
60
+
publicvarwrappedValue:Int
61
+
62
+
publicinit(wrappedValue:Int){
63
+
self.wrappedValue = wrappedValue
64
+
}
65
+
66
+
publicinit(projectedValue:WrapperStruct){
67
+
fatalError()
68
+
}
69
+
70
+
publicvarprojectedValue:WrapperStruct{
71
+
fatalError()
72
+
}
73
+
}
74
+
75
+
classEnumCase{
76
+
@objc
77
+
func foo(@WrapperEnum _ ref:Int)throws{} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
78
+
// expected-note@-1 {{non-'@objc' enums cannot be represented in Objective-C}}
// access-note-adjust{{@objc}} expected-error @-1{{property cannot be marked @objc because its type cannot be represented in Objective-C}}
1646
+
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
1639
1647
}
1640
1648
1641
1649
@objc // access-note-move{{ObjCBase}}
@@ -2649,6 +2657,7 @@ protocol issue51538_P {
2649
2657
func throwingMethod1()throws->Unmanaged<CFArray> // Ok
2650
2658
func throwingMethod2()throws->Unmanaged<issue51538_C> // expected-error {{method cannot be a member of an @objc protocol because its result type cannot be represented in Objective-C}}
2651
2659
// expected-note@-1 {{inferring '@objc' because the declaration is a member of an '@objc' protocol}}
2660
+
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
0 commit comments