Skip to content

Sema: Simplify doesStorageProduceLValue() a bit #35988

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
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
23 changes: 6 additions & 17 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,27 +1019,16 @@ static bool doesStorageProduceLValue(AbstractStorageDecl *storage,
if (!storage->isSetterAccessibleFrom(useDC))
return false;

// If there is no base, or if the base isn't being used, it is settable.
// This is only possible for vars.
if (auto var = dyn_cast<VarDecl>(storage)) {
if (!baseType || var->isStatic())
return true;
}

// If the base is an lvalue, then a reference produces an lvalue.
if (baseType->is<LValueType>())
return true;

// Stored properties of reference types produce lvalues.
if (baseType->hasReferenceSemantics() && storage->hasStorage())
// If there is no base, or the base is an lvalue, then a reference
// produces an lvalue.
if (!baseType || baseType->is<LValueType>())
return true;

// So the base is an rvalue type. The only way an accessor can
// The base is an rvalue type. The only way an accessor can
// produce an lvalue is if we have a property where both the
// getter and setter are nonmutating.
return !storage->hasStorage() &&
!storage->isGetterMutating() &&
!storage->isSetterMutating();
return (!storage->isGetterMutating() &&
!storage->isSetterMutating());
}

Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
Expand Down