Skip to content

Commit 02937a7

Browse files
committed
[Sema] RuntimeMetadata: Supress attr inference for local types
1 parent 74fdd58 commit 02937a7

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7391,7 +7391,7 @@ GetRuntimeDiscoverableAttributes::evaluate(Evaluator &evaluator,
73917391

73927392
auto *NTD = dyn_cast<NominalTypeDecl>(decl);
73937393
// Attribute inference is only possible from protocol conformances.
7394-
if (!NTD || isa<ProtocolDecl>(NTD))
7394+
if (!NTD || isa<ProtocolDecl>(NTD) || NTD->getDeclContext()->isLocalContext())
73957395
return copyAttrs(attrs);
73967396

73977397
// Gather any attributes inferred from (explicit) protocol conformances

test/IRGen/runtime_attributes.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,8 @@ struct FlagWithAvail {
209209
@FlagWithAvail
210210
@available(macOS, obsoleted: 100.0)
211211
func attrIsHigherThanFunc() {}
212+
213+
func test_local_type_with_protocol_conformance() {
214+
// CHECK-NOT: define hidden swiftcc void @"$s18runtime_attributes41test_local_type_with_protocol_conformanceyyF9LocalTest{{.*}}"
215+
struct LocalTest : Ignored {} // Ok but attribute is not inferred.
216+
}

test/type/runtime_discoverable_attrs.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,7 @@ class MembersWithAvailability {
153153
@available(macOS, introduced: 100.0)
154154
var prop: Int { get { 0 } } // Ok
155155
}
156+
157+
func test_local_types_with_conformances() {
158+
struct X : Flagged {}
159+
}

0 commit comments

Comments
 (0)