Skip to content
Closed
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,46 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
++it;
}

// When both a native property and a library function share the same name,
// disambiguate based on call syntax:
// - With parentheses (function call): prefer function members (library)
// - Without parentheses (property access): prefer non-function members (native)
// This mirrors the identifier resolution pattern at lines 3693-3745 where
// VariableDeclarations are preferred without parentheses.
if (possibleMembers.size() > 1)
{
bool hasFunction = false;
bool hasNonFunction = false;
for (auto const& member: possibleMembers)
{
if (member.type->category() == Type::Category::Function)
hasFunction = true;
else
hasNonFunction = true;
}

if (hasFunction && hasNonFunction)
{
MemberList::MemberMap filtered;
if (arguments)
{
// Called with parentheses - keep only functions (library)
for (auto const& member: possibleMembers)
if (member.type->category() == Type::Category::Function)
filtered.push_back(member);
}
else
{
// Accessed without parentheses - keep only non-functions (native property)
for (auto const& member: possibleMembers)
if (member.type->category() != Type::Category::Function)
filtered.push_back(member);
}
if (filtered.size() == 1)
possibleMembers = std::move(filtered);
}
}

annotation.isConstant = false;

if (possibleMembers.empty())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;

// Test that library function is preferred over native property when called with parentheses.
// This allows OpenZeppelin's Address.isContract() to work alongside Tron's native address.isContract property.
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
}

contract C {
using Address for address;

function check(address a) public view returns (bool) {
// With parentheses - should use library function
return a.isContract();
}
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;

// Test that native property is preferred over library function when accessed without parentheses.
// This allows Tron's native address.isContract property to work alongside library functions.
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
}

contract C {
using Address for address;

function check(address a) public view returns (bool) {
// Without parentheses - should use native property
return a.isContract;
}
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;

// Test Tron's native address.isContract property works without library.
contract C {
function check(address a) public view returns (bool) {
return a.isContract;
}
}
// ----