Skip to content

Commit eb30e62

Browse files
authored
Merge pull request #30993 from hborla/property-wrapper-invalid-redeclaration-5.2
[5.2][Property Wrappers] Improve error recovery in buildStorageReference.
2 parents a543bfb + c8bf671 commit eb30e62

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
674674
auto *backing = var->getPropertyWrapperBackingProperty();
675675

676676
// Error recovery.
677-
if (!backing) {
677+
if (!backing || backing->isInvalid()) {
678678
auto type = storage->getValueInterfaceType();
679679
if (isLValue)
680680
type = LValueType::get(type);
@@ -721,7 +721,7 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
721721
auto *backing = var->getPropertyWrapperBackingProperty();
722722

723723
// Error recovery.
724-
if (!backing) {
724+
if (!backing || backing->isInvalid()) {
725725
auto type = storage->getValueInterfaceType();
726726
if (isLValue)
727727
type = LValueType::get(type);

test/decl/var/property_wrappers.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,26 @@ struct S {
825825
var wrappedValue: Int
826826
}
827827

828+
// ---------------------------------------------------------------------------
829+
// Invalid redeclaration
830+
// ---------------------------------------------------------------------------
831+
@propertyWrapper
832+
struct WrapperWithProjectedValue<T> {
833+
var wrappedValue: T
834+
var projectedValue: T { return wrappedValue }
835+
}
836+
837+
class TestInvalidRedeclaration {
838+
@WrapperWithProjectedValue var i = 17
839+
// expected-note@-1 {{'i' previously declared here}}
840+
// expected-note@-2 {{'$i' previously declared here}}
841+
// expected-note@-3 {{'_i' previously declared here}}
842+
@WrapperWithProjectedValue var i = 39
843+
// expected-error@-1 {{invalid redeclaration of 'i'}}
844+
// expected-error@-2 {{invalid redeclaration of '$i'}}
845+
// expected-error@-3 {{invalid redeclaration of '_i'}}
846+
}
847+
828848
// ---------------------------------------------------------------------------
829849
// Closures in initializers
830850
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)