Skip to content

Commit 32c338f

Browse files
committed
[Property Wrappers] Improve error recovery in buildStorageReference.
Bail out if the backing storage has an error type. This can happen if there's an invalid redeclaration of the property wrapper, for example.
1 parent 829f258 commit 32c338f

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
@@ -676,7 +676,7 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
676676
auto *backing = var->getPropertyWrapperBackingProperty();
677677

678678
// Error recovery.
679-
if (!backing)
679+
if (!backing || backing->isInvalid())
680680
return nullptr;
681681

682682
storage = backing;
@@ -719,7 +719,7 @@ static Expr *buildStorageReference(AccessorDecl *accessor,
719719
auto *backing = var->getPropertyWrapperBackingProperty();
720720

721721
// Error recovery.
722-
if (!backing)
722+
if (!backing || backing->isInvalid())
723723
return nullptr;
724724

725725
storage = backing;

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)