Skip to content

[5.1] [SE-0258] More property wrapper fixes #25201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,8 @@ ERROR(numeric_literal_numeric_member,none,
ERROR(standalone_dollar_identifier,none,
"'$' is not an identifier; use backticks to escape it", ())
ERROR(dollar_identifier_decl,none,
"cannot declare entity %0 with a '$' prefix", (Identifier))
"cannot declare entity named %0; the '$' prefix is reserved for "
"implicitly-synthesized declarations", (Identifier))

ERROR(anon_closure_arg_not_in_closure,none,
"anonymous closure argument not contained in a closure", ())
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4370,8 +4370,6 @@ ERROR(property_wrapper_type_requirement_not_accessible,none,
"more restrictive access than its enclosing property wrapper type %3 "
"(which is %select{private|fileprivate|internal|public|open}4)",
(AccessLevel, DescriptiveDeclKind, DeclName, Type, AccessLevel))
ERROR(property_wrapper_reserved_name,none,
"property wrapper type name must start with an uppercase letter", ())

ERROR(property_wrapper_attribute_not_on_property, none,
"property wrapper attribute %0 can only be applied to a property",
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
VarDecl *var) const {
// Determine the type of the backing property.
auto wrapperType = var->getPropertyWrapperBackingPropertyType();
if (!wrapperType)
if (!wrapperType || wrapperType->hasError())
return PropertyWrapperBackingPropertyInfo();

auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo();
Expand Down
24 changes: 0 additions & 24 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,25 +723,6 @@ void TypeChecker::checkDeclAttributesEarly(Decl *D) {
}
}

/// Determine whether the given string is an attribute name that is
/// reserved for the implementation.
static bool isReservedAttributeName(StringRef name) {
for (unsigned i : indices(name)) {
if (name[i] == '_')
continue;

// First character is lowercase; reserved.
if (clang::isLowercase(name[i]))
return true;

// Everything else is reserved.
return false;
}

// All underscores is reserved.
return true;
}

namespace {
class AttributeChecker : public AttributeVisitor<AttributeChecker> {
TypeChecker &TC;
Expand Down Expand Up @@ -2569,11 +2550,6 @@ void AttributeChecker::visitPropertyWrapperAttr(PropertyWrapperAttr *attr) {

// Force checking of the property wrapper type.
(void)nominal->getPropertyWrapperTypeInfo();

// Make sure the name isn't reserved.
if (isReservedAttributeName(nominal->getName().str())) {
nominal->diagnose(diag::property_wrapper_reserved_name);
}
}

void TypeChecker::checkDeclAttributes(Decl *D) {
Expand Down
10 changes: 5 additions & 5 deletions test/Parse/dollar_identifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func escapedDollarAnd() {
`$abc` = 3
}

func $declareWithDollar() { // expected-error{{cannot declare entity '$declareWithDollar' with a '$' prefix}}
var $foo = 17 // expected-error{{cannot declare entity '$foo' with a '$' prefix}}
func $bar() { } // expected-error{{cannot declare entity '$bar' with a '$' prefix}}
func $declareWithDollar() { // expected-error{{cannot declare entity named '$declareWithDollar'}}
var $foo = 17 // expected-error{{cannot declare entity named '$foo'}}
func $bar() { } // expected-error{{cannot declare entity named '$bar'}}
func wibble(
$a: Int, // expected-error{{cannot declare entity '$a' with a '$' prefix}}
$b c: Int) { } // expected-error{{cannot declare entity '$b' with a '$' prefix}}
$a: Int, // expected-error{{cannot declare entity named '$a'}}
$b c: Int) { } // expected-error{{cannot declare entity named '$b'}}
}
2 changes: 1 addition & 1 deletion test/PlaygroundTransform/import_error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// RUN: cp %s %t/main.swift
// RUN: %target-swift-frontend -typecheck -playground %t/main.swift -verify

var $a = 2 // expected-error {{cannot declare entity '$a' with a '$' prefix}}
var $a = 2 // expected-error {{cannot declare entity named '$a'}}
2 changes: 1 addition & 1 deletion test/SourceKit/Sema/sema_playground.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
key.column: 5,
key.filepath: sema_playground.swift,
key.severity: source.diagnostic.severity.error,
key.description: "cannot declare entity '$blah' with a '$' prefix",
key.description: "cannot declare entity named '$blah'; the '$' prefix is reserved for implicitly-synthesized declarations",
key.diagnostic_stage: source.diagnostic.stage.swift.sema
}
]
19 changes: 18 additions & 1 deletion test/decl/var/property_wrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct InitialValueFailableIUO<Value> {
// Property wrapper type definitions
// ---------------------------------------------------------------------------
@_propertyWrapper
struct _lowercaseWrapper<T> { // expected-error{{property wrapper type name must start with an uppercase letter}}
struct _lowercaseWrapper<T> {
var value: T
}

Expand Down Expand Up @@ -714,3 +714,20 @@ struct TestPD {
@PD(a: "foo") var foo: Int = 42 // expected-error{{property 'foo' with attached wrapper cannot initialize both the wrapper type and the property}}
// expected-error@-1{{missing argument for parameter 'initialValue' in call}}
}

protocol P { }

@_propertyWrapper
struct WrapperRequiresP<T: P> {
var value: T
var wrapperValue: T { return value }
}

struct UsesWrapperRequiringP {
// expected-note@-1{{in declaration of}}

@WrapperRequiresP var x.: UsesWrapperRequiringP
// expected-error@-1{{expected member name following '.'}}
// expected-error@-2{{expected declaration}}
// expected-error@-3{{type annotation missing in pattern}}
}