fix <rdar://problem/17051675> Structure initializers in an extension cannot assign to constant properties

Swift SVN r19037
This commit is contained in:
Chris Lattner
2014-06-20 05:45:20 +00:00
parent e7b26e54f1
commit 02bc843f79
2 changed files with 40 additions and 2 deletions

View File

@@ -2020,9 +2020,17 @@ bool VarDecl::isSettable(DeclContext *UseDC) const {
// 'let' properties are generally immutable, unless they are a 'let' ivar
// and we are in the init() for the type that holds the ivar.
if (isLet()) {
if (auto *CD = dyn_cast_or_null<ConstructorDecl>(UseDC))
if (CD->getDeclContext() == getDeclContext())
if (auto *CD = dyn_cast_or_null<ConstructorDecl>(UseDC)) {
auto *DC = getDeclContext();
auto *CDC = CD->getDeclContext();
// If this init is defined inside of the same type (or in an extension
// thereof) as the let property, then it is mutable.
if (CDC->isTypeContext() && DC->isTypeContext() &&
CDC->getDeclaredTypeInContext()->isEqual(
getDeclContext()->getDeclaredTypeInContext()))
return true;
}
return false;
}