Sema: Check mutating-ness of methods irrespective of reference semantics.

Some types are born to mutating methods, and some types have mutating methods thrust upon them. Protocol extensions put classes into the latter category. A 'mutating' protocol extension method requires a mutable 'self' base even when applied to a class. Fix the synthesized getter for lazy properties so that it's only marked 'mutating' on value types, since otherwise it'd now be impossible to access lazy properties on immutable class references.

Fixes part of rdar://problem/21578832, allowing 'mutating' methods from protocol extensions to apply to mutable class references. Properties with mutating setters are still improperly allowed on immutable class reference bases though.

Swift SVN r30557
This commit is contained in:
Joe Groff
2015-07-24 00:10:16 +00:00
parent 2d86296827
commit 58ccc8e160
3 changed files with 68 additions and 4 deletions

View File

@@ -3214,9 +3214,9 @@ ConstraintSystem::simplifyMemberConstraint(const Constraint &constraint) {
return;
}
// If we have an rvalue base of struct or enum type, make sure that the
// If we have an rvalue base, make sure that the
// result isn't mutating (only valid on lvalues).
if (!isMetatype && !baseObjTy->hasReferenceSemantics() &&
if (!isMetatype &&
!baseTy->is<LValueType>() && result->isInstanceMember()) {
if (auto *FD = dyn_cast<FuncDecl>(result))
if (FD->isMutating()) {