Skip to content

[Type Checker] Check subpattern storage instead of whole pattern. #1996

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 1 commit into from
Apr 1, 2016
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: 3 additions & 0 deletions include/swift/AST/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class alignas(8) Pattern {
});
}

/// Does this binding declare something that requires storage?
bool hasStorage() const;

static bool classof(const Pattern *P) { return true; }

//*** Allocation Routines ************************************************/
Expand Down
10 changes: 3 additions & 7 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,10 @@ StaticSpellingKind PatternBindingDecl::getCorrectStaticSpelling() const {
bool PatternBindingDecl::hasStorage() const {
// Walk the pattern, to check to see if any of the VarDecls included in it
// have storage.
bool HasStorage = false;
for (auto entry : getPatternList())
entry.getPattern()->forEachVariable([&](VarDecl *VD) {
if (VD->hasStorage())
HasStorage = true;
});

return HasStorage;
if (entry.getPattern()->hasStorage())
return true;
return false;
}

void PatternBindingDecl::setPattern(unsigned i, Pattern *P) {
Expand Down
10 changes: 10 additions & 0 deletions lib/AST/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ void Pattern::forEachNode(const std::function<void(Pattern*)> &f) {
}
}

bool Pattern::hasStorage() const {
bool HasStorage = false;
forEachVariable([&](VarDecl *VD) {
if (VD->hasStorage())
HasStorage = true;
});

return HasStorage;
}

/// Return true if this is a non-resolved ExprPattern which is syntactically
/// irrefutable.
static bool isIrrefutableExprPattern(const ExprPattern *EP) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
// default-initializable. If so, do it.
if (PBD->getPattern(i)->hasType() &&
!PBD->getInit(i) &&
PBD->hasStorage() &&
PBD->getPattern(i)->hasStorage() &&
!PBD->getPattern(i)->getType()->is<ErrorType>()) {

// If we have a type-adjusting attribute (like ownership), apply it now.
Expand Down
3 changes: 3 additions & 0 deletions test/decl/var/NSManaged_properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class SwiftGizmo : A {
@NSManaged func mutableArrayValueForB() {} // expected-error {{NSManaged method cannot have a body; it must be provided at runtime}}
@NSManaged class func mutableArrayValueForA() {} // expected-error {{@NSManaged only allowed on an instance property or method}}

// SR-1050: don't assert
@NSManaged var multiA, multiB, multiC : NSNumber?

override init() {}
}