pull/2376/head
alpharush 8 months ago
parent 0933dfa67c
commit 759a4fcead
  1. 11
      slither/core/declarations/function.py
  2. 2
      slither/solc_parsing/declarations/function.py
  3. 7
      tests/unit/core/test_data/virtual_overrides.sol
  4. 12
      tests/unit/core/test_virtual_overrides.py

@ -450,17 +450,6 @@ class Function(SourceMapping, metaclass=ABCMeta): # pylint: disable=too-many-pu
###################################################################################
###################################################################################
@property
def is_implemented(self) -> bool:
"""
bool: True if the function is implemented
"""
return self._is_implemented
@is_implemented.setter
def is_implemented(self, is_implemented: bool):
self._is_implemented = is_implemented
@property
def is_virtual(self) -> bool:
"""

@ -262,7 +262,7 @@ class FunctionSolc(CallerContextExpression):
if "overrides" in attributes and isinstance(attributes["overrides"], dict):
for override in attributes["overrides"].get("overrides", []):
refId = override["referencedDeclaration"]
overridden_contract = self.slither_parser._contracts_by_id.get(refId, None)
overridden_contract = self.slither_parser.contracts_by_id.get(refId, None)
if overridden_contract:
overridden_contract.add_reference_from_raw_source(
override["src"], self.compilation_unit

@ -56,3 +56,10 @@ contract A2 is Test2 {
}
}
abstract contract I {
function a() public virtual {}
}
contract J is I {}
contract K is J {
function a() public override {}
}

@ -55,6 +55,18 @@ def test_overrides(solc_binary_path) -> None:
["Y.myVirtualFunction()", "X.myVirtualFunction()"]
)
k = slither.get_contract_from_name("K")[0]
k_virtual_func = k.get_function_from_full_name("a()")
assert not k_virtual_func.is_virtual
assert k_virtual_func.is_override
assert len(k_virtual_func.overrides) == 1
i = slither.get_contract_from_name("I")[0]
i_virtual_func = i.get_function_from_full_name("a()")
assert i_virtual_func.is_virtual
assert not i_virtual_func.is_override
assert len(i_virtual_func.overrides) == 0
assert len(i_virtual_func.overridden_by) == 1
def test_virtual_override_references_and_implementations(solc_binary_path) -> None:
solc_path = solc_binary_path("0.8.15")

Loading…
Cancel
Save