Skip to content

Commit 7f360e6

Browse files
authored
Merge pull request #12781 from ethereum/fixImportDirectiveVisits
Fix import directive visits in type checker and view pure checker.
2 parents 3d8fc6b + 0f1a63c commit 7f360e6

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Compiler Features:
1616

1717
Bugfixes:
1818
* General: Fix internal error for locales with unusual capitalization rules. Locale set in the environment is now completely ignored.
19+
* Type Checker: Fix incorrect type checker errors when importing overloaded functions.
1920
* 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(...)``.
2021

2122

libsolidity/analysis/TypeChecker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ TypePointers TypeChecker::typeCheckMetaTypeFunctionAndRetrieveReturnType(Functio
268268
return {TypeProvider::meta(dynamic_cast<TypeType const&>(*firstArgType).actualType())};
269269
}
270270

271+
bool TypeChecker::visit(ImportDirective const&)
272+
{
273+
return false;
274+
}
275+
271276
void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
272277
{
273278
auto base = dynamic_cast<ContractDefinition const*>(&dereference(_inheritance.name()));

libsolidity/analysis/TypeChecker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class TypeChecker: private ASTConstVisitor
125125
FunctionType const* _functionType
126126
);
127127

128+
bool visit(ImportDirective const&) override;
129+
128130
void endVisit(InheritanceSpecifier const& _inheritance) override;
129131
void endVisit(ModifierDefinition const& _modifier) override;
130132
bool visit(FunctionDefinition const& _function) override;

libsolidity/analysis/ViewPureChecker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ bool ViewPureChecker::check()
134134
return !m_errors;
135135
}
136136

137+
bool ViewPureChecker::visit(ImportDirective const&)
138+
{
139+
return false;
140+
}
141+
137142
bool ViewPureChecker::visit(FunctionDefinition const& _funDef)
138143
{
139144
solAssert(!m_currentFunction, "");

libsolidity/analysis/ViewPureChecker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ViewPureChecker: private ASTConstVisitor
5050
langutil::SourceLocation location;
5151
};
5252

53+
bool visit(ImportDirective const&) override;
54+
5355
bool visit(FunctionDefinition const& _funDef) override;
5456
void endVisit(FunctionDefinition const& _funDef) override;
5557
bool visit(ModifierDefinition const& _modifierDef) override;

libsolidity/formal/SMTEncoder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ void SMTEncoder::endVisit(ContractDefinition const& _contract)
115115
m_context.popSolver();
116116
}
117117

118+
bool SMTEncoder::visit(ImportDirective const&)
119+
{
120+
// do not visit because the identifier therein will confuse us.
121+
return false;
122+
}
123+
118124
void SMTEncoder::endVisit(VariableDeclaration const& _varDecl)
119125
{
120126
// State variables are handled by the constructor.

libsolidity/formal/SMTEncoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class SMTEncoder: public ASTConstVisitor
136136
// because the order of expression evaluation is undefined
137137
// TODO: or just force a certain order, but people might have a different idea about that.
138138

139+
bool visit(ImportDirective const& _node) override;
139140
bool visit(ContractDefinition const& _node) override;
140141
void endVisit(ContractDefinition const& _node) override;
141142
void endVisit(VariableDeclaration const& _node) override;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
==== Source: A ====
2+
function sub(uint256 x, uint256 y) pure returns (uint) { return 1; }
3+
function sub(uint256 x) pure returns (uint) { return 2; }
4+
==== Source: B ====
5+
import {sub} from "A";
6+
contract C
7+
{
8+
function f() public pure returns (uint, uint) {
9+
return (sub(1, 2), sub(2));
10+
}
11+
}
12+
// ====
13+
// compileViaYul: also
14+
// ----
15+
// f() -> 1, 2

0 commit comments

Comments
 (0)