Merge pull request #12781 from ethereum/fixImportDirectiveVisits

Fix import directive visits in type checker and view pure checker.
This commit is contained in:
chriseth 2022-03-14 15:35:37 +01:00 committed by GitHub
commit 7f360e61fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 0 deletions

View File

@ -16,6 +16,7 @@ Compiler Features:
Bugfixes:
* General: Fix internal error for locales with unusual capitalization rules. Locale set in the environment is now completely ignored.
* Type Checker: Fix incorrect type checker errors when importing overloaded functions.
* Yul IR Code Generation: Optimize embedded creation code with correct settings. This fixes potential mismatches between the constructor code of a contract compiled in isolation and the bytecode in ``type(C).creationCode``, resp. the bytecode used for ``new C(...)``.

View File

@ -268,6 +268,11 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
return {TypeProvider::meta(dynamic_cast<TypeType const&>(*firstArgType).actualType())};
}
bool TypeChecker::visit(ImportDirective const&)
{
return false;
}
void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
{
auto base = dynamic_cast<ContractDefinition const*>(&dereference(_inheritance.name()));

View File

@ -125,6 +125,8 @@ private:
FunctionType const* _functionType
);
bool visit(ImportDirective const&) override;
void endVisit(InheritanceSpecifier const& _inheritance) override;
void endVisit(ModifierDefinition const& _modifier) override;
bool visit(FunctionDefinition const& _function) override;

View File

@ -134,6 +134,11 @@ bool ViewPureChecker::check()
return !m_errors;
}
bool ViewPureChecker::visit(ImportDirective const&)
{
return false;
}
bool ViewPureChecker::visit(FunctionDefinition const& _funDef)
{
solAssert(!m_currentFunction, "");

View File

@ -50,6 +50,8 @@ private:
langutil::SourceLocation location;
};
bool visit(ImportDirective const&) override;
bool visit(FunctionDefinition const& _funDef) override;
void endVisit(FunctionDefinition const& _funDef) override;
bool visit(ModifierDefinition const& _modifierDef) override;

View File

@ -115,6 +115,12 @@ void SMTEncoder::endVisit(ContractDefinition const& _contract)
m_context.popSolver();
}
bool SMTEncoder::visit(ImportDirective const&)
{
// do not visit because the identifier therein will confuse us.
return false;
}
void SMTEncoder::endVisit(VariableDeclaration const& _varDecl)
{
// State variables are handled by the constructor.

View File

@ -136,6 +136,7 @@ protected:
// because the order of expression evaluation is undefined
// TODO: or just force a certain order, but people might have a different idea about that.
bool visit(ImportDirective const& _node) override;
bool visit(ContractDefinition const& _node) override;
void endVisit(ContractDefinition const& _node) override;
void endVisit(VariableDeclaration const& _node) override;

View File

@ -0,0 +1,15 @@
==== Source: A ====
function sub(uint256 x, uint256 y) pure returns (uint) { return 1; }
function sub(uint256 x) pure returns (uint) { return 2; }
==== Source: B ====
import {sub} from "A";
contract C
{
function f() public pure returns (uint, uint) {
return (sub(1, 2), sub(2));
}
}
// ====
// compileViaYul: also
// ----
// f() -> 1, 2