fix: disambiguate library functions vs native properties in member access #108
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 functionWithout parentheses (
a.isContract) remains unchanged and will still error with "not unique" when both a native property and library function exist.Changes
libsolidity/analysis/TypeChecker.cpp: Added disambiguation logic to filter out non-functions when called with parenthesestest/libsolidity/syntaxTests/memberLookup/:library_function_vs_native_property_with_parens.sol- verifies library function is used with()native_isContract_property.sol- verifies native property still works standaloneBehavior After Fix
addr.isContract()addr.isContract(nousing for)addr.isContract(withusing for)Motivation
This enables Hyperlane and other protocols using OpenZeppelin contracts to deploy on Tron without modification.