Skip to content

Commit ffd5d96

Browse files
committed
[AST] RuntimeMetadata: Reject attributes with custom arguments on protocol declarations
1 parent 42694d8 commit ffd5d96

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6939,6 +6939,11 @@ ERROR(runtime_attribute_type_requirement_not_accessible,none,
69396939
"(which is %select{private|fileprivate|internal|package|public|open}4)",
69406940
(AccessLevel, DescriptiveDeclKind, DeclName, Type, AccessLevel))
69416941

6942+
ERROR(cannot_use_attr_with_custom_arguments_on_protocol,none,
6943+
"reflection metadata attributes applied to protocols cannot have"
6944+
" additional attribute arguments; attribute arguments must be"
6945+
" explicitly written on the conforming type",
6946+
())
69426947

69436948
#define UNDEFINE_DIAGNOSTIC_MACROS
69446949
#include "DefineDiagnosticMacros.h"

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3689,6 +3689,10 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
36893689
case DeclKind::Protocol: {
36903690
// Allow on protocols because they are sources
36913691
// of inference.
3692+
if (attr->hasArgs()) {
3693+
diagnoseAndRemoveAttr(
3694+
attr, diag::cannot_use_attr_with_custom_arguments_on_protocol);
3695+
}
36923696
return;
36933697
}
36943698

test/type/runtime_discoverable_attrs.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,12 @@ struct TestNoAmbiguity {
130130
@Flag func testInst(_: Int, _: Int) {} // Ok
131131
}
132132

133-
@Flag("flag from protocol")
133+
@Flag
134134
protocol Flagged {}
135135

136+
@Flag("flag from protocol") // expected-error {{reflection metadata attributes applied to protocols cannot have additional attribute arguments}}
137+
protocol InvalidFlagged {}
138+
136139
struct Inference1 : Flagged {} // Ok
137140
class Inference2 : Flagged {} // Ok
138141
enum Inference3 : Flagged {} // Ok
@@ -277,7 +280,7 @@ extension EnumFlag where B == Void {
277280
}
278281

279282
@available(*, unavailable)
280-
@EnumFlag extension EnumTypeTest { // expected-error {{@EnumFlag is already applied to type 'EnumTypeTest'; did you want to remove it?}} {{266:1-11=}}
283+
@EnumFlag extension EnumTypeTest { // expected-error {{@EnumFlag is already applied to type 'EnumTypeTest'; did you want to remove it?}} {{269:1-11=}}
281284
}
282285

283286
@available(*, unavailable)

0 commit comments

Comments
 (0)