Skip to content

Commit 4ae9c8c

Browse files
author
Harlan Haskins
committed
[Sema] Non-requirement protocol members should inherit @usableFromInline
Previously, members of protocols that were not protocol requirements, like accessors and typealiases, did not inherit @usableFromInline from the parent protocol. Change this so they do.
1 parent be9dda1 commit 4ae9c8c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,8 +2411,7 @@ bool ValueDecl::isUsableFromInline() const {
24112411
return true;
24122412

24132413
if (auto *containingProto = dyn_cast<ProtocolDecl>(getDeclContext())) {
2414-
if (isProtocolRequirement() &&
2415-
containingProto->getAttrs().hasAttribute<UsableFromInlineAttr>())
2414+
if (containingProto->getAttrs().hasAttribute<UsableFromInlineAttr>())
24162415
return true;
24172416
}
24182417

test/Compatibility/attr_inlinable_swift42.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ enum InternalEnum {
1717
case persimmon(String)
1818
}
1919

20+
@usableFromInline protocol P {
21+
typealias T = Int
22+
}
23+
24+
extension P {
25+
@inlinable func f() {
26+
_ = T.self // typealiases were not checked in Swift 4.2, but P.T inherits @usableFromInline in Swift 4.2 mode
27+
}
28+
}

test/attr/attr_inlinable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,13 @@ public struct KeypathStruct {
248248
// expected-error@-1 {{property 'x' is internal and cannot be referenced from an '@inlinable' function}}
249249
}
250250
}
251+
@usableFromInline protocol P {
252+
typealias T = Int
253+
}
254+
255+
extension P {
256+
@inlinable func f() {
257+
_ = T.self // ok, typealias inherits @usableFromInline from P
258+
}
259+
}
260+

0 commit comments

Comments
 (0)