Skip to content

Commit 873d46f

Browse files
committed
Stop complaining about shadowing parameters of functions without bodies
1 parent 085bede commit 873d46f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

libsolidity/analysis/DeclarationContainer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ bool DeclarationContainer::registerDeclaration(
124124
// Do not warn about shadowing for structs and enums because their members are
125125
// not accessible without prefixes. Also do not warn about event parameters
126126
// because they do not participate in any proper scope.
127-
bool special = _declaration.scope() && (_declaration.isStructMember() || _declaration.isEnumValue() || _declaration.isEventParameter());
127+
128+
FunctionDefinition const* functionDefinitionScope = dynamic_cast<FunctionDefinition const*>(_declaration.scope());
129+
bool special = _declaration.scope() && (_declaration.isStructMember() || _declaration.isEnumValue() || _declaration.isEventParameter()) ||
130+
functionDefinitionScope && !functionDefinitionScope->hasBody(); // parameter of a function without body
128131
if (m_enclosingContainer && !special)
129132
m_homonymCandidates.emplace_back(*_name, _location ? _location : &_declaration.location());
130133
}

libsolidity/ast/AST.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ class FunctionDefinition: public CallableDeclaration, public StructurallyDocumen
853853
Token kind() const { return m_kind; }
854854
bool isPayable() const { return m_stateMutability == StateMutability::Payable; }
855855
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
856+
bool hasBody() const { return m_body != nullptr; }
856857
Block const& body() const { solAssert(m_body, ""); return *m_body; }
857858
Visibility defaultVisibility() const override;
858859
bool isVisibleInContract() const override
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
abstract contract A {
2+
function f(uint A) public {} // warning
3+
function g(uint A) public virtual; // OK
4+
}
5+
6+
contract C {
7+
function f(uint C) public pure {} // warning
8+
}
9+
// ----
10+
// Warning 2519: (37-43): This declaration shadows an existing declaration.
11+
// Warning 2519: (148-154): This declaration shadows an existing declaration.

0 commit comments

Comments
 (0)