Skip to content

Commit 0ad7d8b

Browse files
committed
[AST] Prevent use of @extensible without ExtensibleAttribute feature
1 parent 6d89bca commit 0ad7d8b

6 files changed

+26
-7
lines changed

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ SIMPLE_DECL_ATTR(extensible, Extensible,
880880
OnEnum,
881881
ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove | ForbiddenInABIAttr,
882882
169)
883+
DECL_ATTR_FEATURE_REQUIREMENT(Extensible, ExtensibleAttribute)
883884

884885
SIMPLE_DECL_ATTR(concurrent, Concurrent,
885886
OnFunc | OnConstructor | OnSubscript | OnVar,

test/IDE/complete_decl_attribute.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ struct _S {
330330
// ON_MEMBER_LAST-DAG: Keyword/None: freestanding[#Declaration Attribute#]; name=freestanding
331331
// ON_MEMBER_LAST-DAG: Keyword/None: storageRestrictions[#Declaration Attribute#]; name=storageRestrictions
332332
// ON_MEMBER_LAST-DAG: Keyword/None: lifetime[#Declaration Attribute#]; name=lifetime
333-
// ON_MEMBER_LAST-DAG: Keyword/None: extensible[#Declaration Attribute#]; name=extensible
334333
// ON_MEMBER_LAST-DAG: Keyword/None: concurrent[#Declaration Attribute#]; name=concurrent
335334
// ON_MEMBER_LAST-NOT: Keyword
336335
// ON_MEMBER_LAST-DAG: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
@@ -404,7 +403,6 @@ func dummy2() {}
404403
// KEYWORD_LAST-DAG: Keyword/None: attached[#Declaration Attribute#]; name=attached
405404
// KEYWORD_LAST-DAG: Keyword/None: storageRestrictions[#Declaration Attribute#]; name=storageRestrictions
406405
// KEYWORD_LAST-DAG: Keyword/None: lifetime[#Declaration Attribute#]; name=lifetime
407-
// KEYWORD_LAST-DAG: Keyword/None: extensible[#Declaration Attribute#]; name=extensible
408406
// KEYWORD_LAST-DAG: Keyword/None: concurrent[#Declaration Attribute#]; name=concurrent
409407
// KEYWORD_LAST-NOT: Keyword
410408
// KEYWORD_LAST-DAG: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct

test/IDE/complete_decl_attribute_feature_requirement.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
// RUN: %batch-code-completion -filecheck-additional-suffix _DISABLED
99
// RUN: %batch-code-completion -filecheck-additional-suffix _ENABLED \
10-
// RUN: -enable-experimental-feature ABIAttribute
10+
// RUN: -enable-experimental-feature ABIAttribute \
11+
// RUN: -enable-experimental-feature ExtensibleAttribute
1112

1213
// NOTE: Please do not include the ", N items" after "Begin completions". The
1314
// item count creates needless merge conflicts given that an "End completions"
@@ -34,6 +35,8 @@
3435
// KEYWORD4: Begin completions
3536
// KEYWORD4_ENABLED-NOT: Keyword/None: abi[#{{.*}} Attribute#]; name=abi
3637
// KEYWORD4_DISABLED-NOT: Keyword/None: abi[#{{.*}} Attribute#]; name=abi
38+
// KEYWORD4_ENABLED-DAG: Keyword/None: extensible[#{{.*}} Attribute#]; name=extensible
39+
// KEYWORD4_DISABLED-NOT: Keyword/None: extensible[#{{.*}} Attribute#]; name=extensible
3740
// KEYWORD4: End completions
3841

3942
@#^KEYWORD5^# struct S{}

test/ModuleInterface/extensible_enums.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/// Build the library
66
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
77
// RUN: -module-name Lib \
8-
// RUN: -emit-module-path %t/Lib.swiftmodule
8+
// RUN: -emit-module-path %t/Lib.swiftmodule \
9+
// RUN: -enable-experimental-feature ExtensibleAttribute
910

1011
// Check that the errors are produced when using enums from module with `ExtensibleEnums` feature enabled.
1112
// RUN: %target-swift-frontend -typecheck %t/src/TestChecking.swift \
@@ -18,14 +19,18 @@
1819
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
1920
// RUN: -module-name Lib \
2021
// RUN: -package-name Test \
21-
// RUN: -emit-module-path %t/Lib.swiftmodule
22+
// RUN: -emit-module-path %t/Lib.swiftmodule \
23+
// RUN: -enable-experimental-feature ExtensibleAttribute
24+
2225

2326
// Different module but the same package
2427
// RUN: %target-swift-frontend -typecheck %t/src/TestSamePackage.swift \
2528
// RUN: -swift-version 5 -module-name Client -I %t \
2629
// RUN: -package-name Test \
2730
// RUN: -verify
2831

32+
// REQUIRES: swift_feature_ExtensibleAttribute
33+
2934
//--- Lib.swift
3035

3136
@extensible

test/attr/attr_extensible.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ExtensibleAttribute
2+
3+
// REQUIRES: swift_feature_ExtensibleAttribute
24

35
@extensible
46
public enum E1 { // Ok

test/attr/feature_requirement.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-typecheck-verify-swift -parse-as-library -disable-experimental-parser-round-trip -verify-additional-prefix disabled-
2-
// RUN: %target-typecheck-verify-swift -parse-as-library -verify-additional-prefix enabled- -enable-experimental-feature ABIAttribute
2+
// RUN: %target-typecheck-verify-swift -parse-as-library -verify-additional-prefix enabled- -enable-experimental-feature ABIAttribute -enable-experimental-feature ExtensibleAttribute
33

44
// REQUIRES: asserts
55

@@ -14,3 +14,13 @@ func fn() {} // expected-disabled-error@-1 {{'abi' attribute is only valid when
1414
#else
1515
#error("doesn't have @abi") // expected-disabled-error {{doesn't have @abi}}
1616
#endif
17+
18+
@extensible
19+
public enum E {} // expected-disabled-error@-1 {{'extensible' attribute is only valid when experimental feature ExtensibleAttribute is enabled}}
20+
21+
#if hasAttribute(extensible)
22+
#error("does have @extensible") // expected-enabled-error {{does have @extensible}}
23+
#else
24+
#error("doesn't have @extensible") // expected-disabled-error {{doesn't have @extensible}}
25+
#endif
26+

0 commit comments

Comments
 (0)