Skip to content
Draft
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
31 changes: 23 additions & 8 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3249,13 +3249,26 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
{
if (ContractType const* contractType = dynamic_cast<decltype(contractType)>(typeType->actualType()))
{
// ContractType has only user defined members, so annotation.referencedDeclaration is not NULL.
solAssert(annotation.referencedDeclaration);
annotation.isLValue = annotation.referencedDeclaration->isLValue();
// In case an expression `C.foo`, where `foo` is a function, assign C's purity to `C.foo`.
// This does not allow to assign it to a constant variable, because of different kind.
// Left-hand side of the variable declaration statement never has `Declaration` kind. It is used only to
// mark, that a function containing only such an expression has no effect.
if (
auto const* functionType = dynamic_cast<FunctionType const*>(annotation.type);
functionType &&
functionType->kind() == FunctionType::Kind::Declaration
)
annotation.isPure = *_memberAccess.expression().annotation().isPure;
// In case `Base.value` or `Lib.value` and when `value` is constant, the whole expression is pure.
else if (
auto const* varDecl = dynamic_cast<VariableDeclaration const*>(annotation.referencedDeclaration);
varDecl &&
varDecl->isConstant()
)
annotation.isPure = true;
}
else
annotation.isLValue = false;
Expand Down Expand Up @@ -3322,14 +3335,6 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
annotation.isPure = true;
}

if (
auto const* varDecl = dynamic_cast<VariableDeclaration const*>(annotation.referencedDeclaration);
!annotation.isPure.set() &&
varDecl &&
varDecl->isConstant()
)
annotation.isPure = true;

if (auto magicType = dynamic_cast<MagicType const*>(exprType))
{
if (magicType->kind() == MagicType::Kind::ABI)
Expand Down Expand Up @@ -3409,6 +3414,16 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
if (!annotation.isPure.set())
annotation.isPure = false;

if (
auto const* funcType = dynamic_cast<FunctionType const*>(annotation.type);
funcType &&
funcType->kind() != FunctionType::Kind::Declaration &&
funcType->kind() != FunctionType::Kind::Internal &&
funcType->kind() != FunctionType::Kind::Error &&
funcType->kind() != FunctionType::Kind::Event
)
solAssert(funcType->isPure() == *annotation.isPure);

return false;
}

Expand Down