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
@_implementationOnly: fix over-eager checking for vars in extensions (#24629)
The logic I had here checked whether an extension used an
implementation-only type whenever there was a declaration within that
extension that needed checking...but unfortunately that included not
just PatternBindingDecls (whose access is filtered at a later step)
but things like IfConfigDecls (#if). Change this to only check
signatures of extensions with ABI-public members, something that is
tested once when visiting an ExtensionDecl.
Additionally, skip AccessorDecls entirely, since they'll be tested
as part of the corresponding subscript or var. This saves a duplicate
diagnostic.
rdar://problem/50541589
Copy file name to clipboardExpand all lines: test/Sema/implementation-only-import-in-decls.swift
+14-6Lines changed: 14 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -86,27 +86,35 @@ public var (testBadTypeTuplePartlyInferred3, testBadTypeTuplePartlyInferred4): (
86
86
publicvartestMultipleBindings1:Int?=nil,testMultipleBindings2:BadStruct?=nil // expected-error {{cannot use struct 'BadStruct' here; 'BADLibrary' has been imported as implementation-only}}
87
87
publicvartestMultipleBindings3:BadStruct?=nil,testMultipleBindings4:Int?=nil // expected-error {{cannot use struct 'BadStruct' here; 'BADLibrary' has been imported as implementation-only}}
88
88
89
-
extensionBadStruct{ // expected-error {{cannot use struct 'BadStruct' here; 'BADLibrary' has been imported as implementation-only}}
90
-
publicfunc testExtensionOfBadType(){} // FIXME: Should complain here instead of at the extension decl.
89
+
extensionBadStruct{ // expected-error {{cannot use struct 'BadStruct' in an extension with public or '@usableFromInline' members; 'BADLibrary' has been imported as implementation-only}}
90
+
publicfunc testExtensionOfBadType(){}
91
+
publicvartestExtensionVarBad:Int{0}
92
+
public subscript(bad _:Int)->Int{0}
91
93
}
92
94
extensionBadStruct{
93
95
func testExtensionOfOkayType(){}
96
+
vartestExtensionVarOkay:Int{0}
97
+
subscript(okay _:Int)->Int{0}
94
98
}
95
99
96
-
extensionArraywhere Element ==BadStruct{ // expected-error {{cannot use struct 'BadStruct' here; 'BADLibrary' has been imported as implementation-only}}
97
-
publicfunc testExtensionWithBadRequirement(){} // FIXME: Should complain here instead of at the extension decl.
100
+
extensionArraywhere Element ==BadStruct{ // expected-error {{cannot use struct 'BadStruct' in an extension with public or '@usableFromInline' members; 'BADLibrary' has been imported as implementation-only}}
101
+
publicfunc testExtensionWithBadRequirement(){}
102
+
publicvartestExtensionVarBad:Int{0}
103
+
public subscript(bad _:Int)->Int{0}
98
104
}
99
105
100
106
extensionArraywhere Element ==BadStruct{
101
107
func testExtensionWithOkayRequirement(){} // okay
108
+
vartestExtensionVarOkay:Int{0} // okay
109
+
subscript(okay _:Int)->Int{0} // okay
102
110
}
103
111
104
112
extensionInt:BadProto{} // expected-error {{cannot use protocol 'BadProto' here; 'BADLibrary' has been imported as implementation-only}}
extensionArray:TestConstrainedExtensionProtowhere Element ==BadStruct{ // expected-error {{cannot use struct 'BadStruct' here; 'BADLibrary' has been imported as implementation-only}}
117
+
extensionArray:TestConstrainedExtensionProtowhere Element ==BadStruct{ // expected-error {{cannot use struct 'BadStruct' in an extension with conditional conformances; 'BADLibrary' has been imported as implementation-only}}
110
118
}
111
119
112
120
@@ -165,7 +173,7 @@ public class SubclassOfNormalClass: NormalClass {}
165
173
publicfunc testInheritedConformance(_:NormalProtoAssocHolder<SubclassOfNormalClass>){} // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
166
174
publicfunc testSpecializedConformance(_:NormalProtoAssocHolder<GenericStruct<Int>>){} // expected-error {{cannot use conformance of 'GenericStruct<T>' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
167
175
168
-
extensionArraywhere Element ==NormalProtoAssocHolder<NormalStruct>{ // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
176
+
extensionArraywhere Element ==NormalProtoAssocHolder<NormalStruct>{ // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in an extension with public or '@usableFromInline' members; 'BADLibrary' has been imported as implementation-only}}
0 commit comments