Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusaaguiar committed Nov 21, 2024
1 parent 666b499 commit 5645314
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,43 @@ bool TypeChecker::visit(ImportDirective const&)
return false;
}

void TypeChecker::endVisit(ContractDefinition const& _contract)
{
if (
ASTPointer<Expression> const baseLocation = _contract.storageBaseLocationExpression()
)
{
if (!*baseLocation->annotation().isPure)
{
if (auto functionCall = dynamic_cast<FunctionCall const*>(baseLocation.get()))
if (
auto const* identifier = dynamic_cast<Identifier const*>(&functionCall->expression());
identifier && identifier->name() == "erc7201"
)
return;

m_errorReporter.typeError(
77_error,
baseLocation->location(),
"The contract base location must be an expression that can be evaluated at compilation time."
);
}
auto const* expressionType = type(*baseLocation);
BoolResult result = expressionType->isImplicitlyConvertibleTo(*TypeProvider::uint256());
if (!result)
{
m_errorReporter.typeErrorConcatenateDescriptions(
76_error,
baseLocation->location(),
"Contract storage base location must be "
"in range of type uint256. Current type is " +
expressionType->humanReadableName(),
result.message()
);
}
}
}

void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
{
auto base = dynamic_cast<ContractDefinition const*>(&dereference(_inheritance.name()));
Expand Down
1 change: 1 addition & 0 deletions libsolidity/analysis/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class TypeChecker: private ASTConstVisitor
void endVisit(ElementaryTypeNameExpression const& _expr) override;
void endVisit(Literal const& _literal) override;
void endVisit(UsingForDirective const& _usingForDirective) override;
void endVisit(ContractDefinition const& _contract) override;

void checkErrorAndEventParameters(CallableDeclaration const& _callable);

Expand Down
2 changes: 2 additions & 0 deletions libsolidity/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ class ContractDefinition: public Declaration, public StructurallyDocumented, pub
/// Returns the ether receiver function or nullptr if no receive function was specified.
FunctionDefinition const* receiveFunction() const;

ASTPointer<Expression> const& storageBaseLocationExpression() const { return m_storageBaseLocationExpression; }

std::string fullyQualifiedName() const { return sourceUnitName() + ":" + name(); }

Type const* type() const override;
Expand Down

0 comments on commit 5645314

Please sign in to comment.