fix: disambiguate library functions vs native properties in member access #107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an issue where using OpenZeppelin's
Address.isContract()library function on Tron causes a compilation error:This happens because Tron's native
address.isContractproperty (added in TIP-44) conflicts with library functions attached viausing Address for address;.Problem
When code uses:
The compiler finds two members named
isContract:address.isContract(boolean, uses ISCONTRACT opcode)Address.isContract(address)attached viausing forSolution
Disambiguate based on call syntax:
a.isContract(): prefer library functiona.isContract: prefer native propertyThis mirrors the existing identifier resolution pattern in
visit(Identifier)(lines 3693-3745 in TypeChecker.cpp) whereVariableDeclarations are preferred without parentheses.Changes
libsolidity/analysis/TypeChecker.cpp: Added disambiguation logic after overload resolutiontest/libsolidity/syntaxTests/memberLookup/:library_function_vs_native_property_with_parens.sol- verifies library function is used with()library_function_vs_native_property_without_parens.sol- verifies native property is used without()native_isContract_property.sol- verifies native property still works standaloneBehavior After Fix
addr.isContract()addr.isContractMotivation
This enables Hyperlane and other protocols using OpenZeppelin contracts to deploy on Tron without modification.