Skip to content

Commit a3b5430

Browse files
committed
[Frontend] Mark 'Type Wrappers' as experimental feature that has to be enabled
1 parent 7d28a4f commit a3b5430

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6480,6 +6480,9 @@ ERROR(move_expression_not_passed_lvalue,none,
64806480
// MARK: Type Wrappers
64816481
//------------------------------------------------------------------------------
64826482

6483+
ERROR(type_wrappers_are_experimental,none,
6484+
"type wrappers are an experimental feature", ())
6485+
64836486
ERROR(type_wrapper_attribute_not_allowed_here,none,
64846487
"type wrapper attribute %0 can only be applied to a class, struct",
64856488
(Identifier))

include/swift/Basic/Features.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ EXPERIMENTAL_FEATURE(SendableCompletionHandlers)
122122
/// Enables opaque type erasure without also enabling implict dynamic
123123
EXPERIMENTAL_FEATURE(OpaqueTypeErasure)
124124

125+
/// Whether to enable experimental @typeWrapper feature which allows to
126+
/// declare a type that controls access to all stored properties of the
127+
/// wrapped type.
128+
EXPERIMENTAL_FEATURE(TypeWrappers)
129+
125130
#undef EXPERIMENTAL_FEATURE
126131
#undef UPCOMING_FEATURE
127132
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,6 +2935,10 @@ static bool usesFeatureSpecializeAttributeWithAvailability(Decl *decl) {
29352935
return false;
29362936
}
29372937

2938+
static bool usesFeatureTypeWrappers(Decl *decl) {
2939+
return decl->getAttrs().hasAttribute<TypeWrapperAttr>();
2940+
}
2941+
29382942
static void suppressingFeatureSpecializeAttributeWithAvailability(
29392943
PrintOptions &options,
29402944
llvm::function_ref<void()> action) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,6 +3587,12 @@ void AttributeChecker::visitPropertyWrapperAttr(PropertyWrapperAttr *attr) {
35873587
}
35883588

35893589
void AttributeChecker::visitTypeWrapperAttr(TypeWrapperAttr *attr) {
3590+
if (!Ctx.LangOpts.hasFeature(Feature::TypeWrappers)) {
3591+
diagnose(attr->getLocation(), diag::type_wrappers_are_experimental);
3592+
attr->setInvalid();
3593+
return;
3594+
}
3595+
35903596
auto nominal = dyn_cast<NominalTypeDecl>(D);
35913597
if (!nominal)
35923598
return;

test/Interpreter/type_wrappers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -parse-as-library -emit-library -emit-module-path %t/type_wrapper_defs.swiftmodule -module-name type_wrapper_defs %S/Inputs/type_wrapper_defs.swift -o %t/%target-library-name(type_wrapper_defs)
2+
// RUN: %target-build-swift -enable-experimental-feature TypeWrappers -parse-as-library -emit-library -emit-module-path %t/type_wrapper_defs.swiftmodule -module-name type_wrapper_defs %S/Inputs/type_wrapper_defs.swift -o %t/%target-library-name(type_wrapper_defs)
33
// RUN: %target-build-swift -ltype_wrapper_defs -module-name main -I %t -L %t %s -o %t/a.out
44
// RUN: %target-run %t/a.out | %FileCheck %s
55

test/type/type_wrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature TypeWrappers
22

33
@typeWrapper
44
struct ConcreteTypeWrapper { // expected-error {{type wrapper has to declare a single generic parameter for underlying storage type}}

0 commit comments

Comments
 (0)