Skip to content

Commit e5aafaa

Browse files
authored
Merge pull request #25201 from DougGregor/property-wrappers-more-fixes
[5.1] [SE-0258] More property wrapper fixes
2 parents f67d8bd + 1d5c534 commit e5aafaa

File tree

8 files changed

+28
-36
lines changed

8 files changed

+28
-36
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,8 @@ ERROR(numeric_literal_numeric_member,none,
11101110
ERROR(standalone_dollar_identifier,none,
11111111
"'$' is not an identifier; use backticks to escape it", ())
11121112
ERROR(dollar_identifier_decl,none,
1113-
"cannot declare entity %0 with a '$' prefix", (Identifier))
1113+
"cannot declare entity named %0; the '$' prefix is reserved for "
1114+
"implicitly-synthesized declarations", (Identifier))
11141115

11151116
ERROR(anon_closure_arg_not_in_closure,none,
11161117
"anonymous closure argument not contained in a closure", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,8 +4370,6 @@ ERROR(property_wrapper_type_requirement_not_accessible,none,
43704370
"more restrictive access than its enclosing property wrapper type %3 "
43714371
"(which is %select{private|fileprivate|internal|public|open}4)",
43724372
(AccessLevel, DescriptiveDeclKind, DeclName, Type, AccessLevel))
4373-
ERROR(property_wrapper_reserved_name,none,
4374-
"property wrapper type name must start with an uppercase letter", ())
43754373

43764374
ERROR(property_wrapper_attribute_not_on_property, none,
43774375
"property wrapper attribute %0 can only be applied to a property",

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
15591559
VarDecl *var) const {
15601560
// Determine the type of the backing property.
15611561
auto wrapperType = var->getPropertyWrapperBackingPropertyType();
1562-
if (!wrapperType)
1562+
if (!wrapperType || wrapperType->hasError())
15631563
return PropertyWrapperBackingPropertyInfo();
15641564

15651565
auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo();

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -723,25 +723,6 @@ void TypeChecker::checkDeclAttributesEarly(Decl *D) {
723723
}
724724
}
725725

726-
/// Determine whether the given string is an attribute name that is
727-
/// reserved for the implementation.
728-
static bool isReservedAttributeName(StringRef name) {
729-
for (unsigned i : indices(name)) {
730-
if (name[i] == '_')
731-
continue;
732-
733-
// First character is lowercase; reserved.
734-
if (clang::isLowercase(name[i]))
735-
return true;
736-
737-
// Everything else is reserved.
738-
return false;
739-
}
740-
741-
// All underscores is reserved.
742-
return true;
743-
}
744-
745726
namespace {
746727
class AttributeChecker : public AttributeVisitor<AttributeChecker> {
747728
TypeChecker &TC;
@@ -2569,11 +2550,6 @@ void AttributeChecker::visitPropertyWrapperAttr(PropertyWrapperAttr *attr) {
25692550

25702551
// Force checking of the property wrapper type.
25712552
(void)nominal->getPropertyWrapperTypeInfo();
2572-
2573-
// Make sure the name isn't reserved.
2574-
if (isReservedAttributeName(nominal->getName().str())) {
2575-
nominal->diagnose(diag::property_wrapper_reserved_name);
2576-
}
25772553
}
25782554

25792555
void TypeChecker::checkDeclAttributes(Decl *D) {

test/Parse/dollar_identifier.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ func escapedDollarAnd() {
6262
`$abc` = 3
6363
}
6464

65-
func $declareWithDollar() { // expected-error{{cannot declare entity '$declareWithDollar' with a '$' prefix}}
66-
var $foo = 17 // expected-error{{cannot declare entity '$foo' with a '$' prefix}}
67-
func $bar() { } // expected-error{{cannot declare entity '$bar' with a '$' prefix}}
65+
func $declareWithDollar() { // expected-error{{cannot declare entity named '$declareWithDollar'}}
66+
var $foo = 17 // expected-error{{cannot declare entity named '$foo'}}
67+
func $bar() { } // expected-error{{cannot declare entity named '$bar'}}
6868
func wibble(
69-
$a: Int, // expected-error{{cannot declare entity '$a' with a '$' prefix}}
70-
$b c: Int) { } // expected-error{{cannot declare entity '$b' with a '$' prefix}}
69+
$a: Int, // expected-error{{cannot declare entity named '$a'}}
70+
$b c: Int) { } // expected-error{{cannot declare entity named '$b'}}
7171
}

test/PlaygroundTransform/import_error.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// RUN: cp %s %t/main.swift
33
// RUN: %target-swift-frontend -typecheck -playground %t/main.swift -verify
44

5-
var $a = 2 // expected-error {{cannot declare entity '$a' with a '$' prefix}}
5+
var $a = 2 // expected-error {{cannot declare entity named '$a'}}

test/SourceKit/Sema/sema_playground.swift.response

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
key.column: 5,
1212
key.filepath: sema_playground.swift,
1313
key.severity: source.diagnostic.severity.error,
14-
key.description: "cannot declare entity '$blah' with a '$' prefix",
14+
key.description: "cannot declare entity named '$blah'; the '$' prefix is reserved for implicitly-synthesized declarations",
1515
key.diagnostic_stage: source.diagnostic.stage.swift.sema
1616
}
1717
]

test/decl/var/property_wrappers.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct InitialValueFailableIUO<Value> {
108108
// Property wrapper type definitions
109109
// ---------------------------------------------------------------------------
110110
@_propertyWrapper
111-
struct _lowercaseWrapper<T> { // expected-error{{property wrapper type name must start with an uppercase letter}}
111+
struct _lowercaseWrapper<T> {
112112
var value: T
113113
}
114114

@@ -714,3 +714,20 @@ struct TestPD {
714714
@PD(a: "foo") var foo: Int = 42 // expected-error{{property 'foo' with attached wrapper cannot initialize both the wrapper type and the property}}
715715
// expected-error@-1{{missing argument for parameter 'initialValue' in call}}
716716
}
717+
718+
protocol P { }
719+
720+
@_propertyWrapper
721+
struct WrapperRequiresP<T: P> {
722+
var value: T
723+
var wrapperValue: T { return value }
724+
}
725+
726+
struct UsesWrapperRequiringP {
727+
// expected-note@-1{{in declaration of}}
728+
729+
@WrapperRequiresP var x.: UsesWrapperRequiringP
730+
// expected-error@-1{{expected member name following '.'}}
731+
// expected-error@-2{{expected declaration}}
732+
// expected-error@-3{{type annotation missing in pattern}}
733+
}

0 commit comments

Comments
 (0)