support duplicated func name for diff types in global using for

pull/1625/head
alpharush 2 years ago
parent cf5e3bee6b
commit 9e7ff8fd1d
  1. 9
      slither/slithir/convert.py
  2. 16
      slither/solc_parsing/declarations/using_for_top_level.py

@ -525,9 +525,7 @@ def _convert_type_contract(ir: Member) -> Assignment:
raise SlithIRError(f"type({contract.name}).{ir.variable_right} is unknown") raise SlithIRError(f"type({contract.name}).{ir.variable_right} is unknown")
def propagate_types( def propagate_types(ir: Operation, node: "Node"): # pylint: disable=too-many-locals
ir: slither.slithir.operations.operation.Operation, node: "Node"
): # pylint: disable=too-many-locals
# propagate the type # propagate the type
node_function = node.function node_function = node.function
using_for = ( using_for = (
@ -1425,9 +1423,8 @@ def look_for_library_or_top_level(
for destination in using_for[t]: for destination in using_for[t]:
if isinstance(destination, FunctionTopLevel) and destination.name == ir.function_name: if isinstance(destination, FunctionTopLevel) and destination.name == ir.function_name:
arguments = [ir.destination] + ir.arguments arguments = [ir.destination] + ir.arguments
if ( if len(destination.parameters) == len(arguments) and _find_function_from_parameter(
len(destination.parameters) == len(arguments) arguments, [destination], True
and _find_function_from_parameter(arguments, [destination], True) is not None
): ):
internalcall = InternalCall(destination, ir.nbr_arguments, ir.lvalue, ir.type_call) internalcall = InternalCall(destination, ir.nbr_arguments, ir.lvalue, ir.type_call)
internalcall.set_expression(ir.expression) internalcall.set_expression(ir.expression)

@ -49,7 +49,7 @@ class UsingForTopLevelSolc(CallerContextExpression): # pylint: disable=too-few-
type_name = parse_type(self._type_name, self) type_name = parse_type(self._type_name, self)
self._using_for.using_for[type_name] = [] self._using_for.using_for[type_name] = []
if self._library_name is not None: if self._library_name:
library_name = parse_type(self._library_name, self) library_name = parse_type(self._library_name, self)
self._using_for.using_for[type_name].append(library_name) self._using_for.using_for[type_name].append(library_name)
self._propagate_global(type_name) self._propagate_global(type_name)
@ -91,7 +91,12 @@ class UsingForTopLevelSolc(CallerContextExpression): # pylint: disable=too-few-
self, function_name: str, type_name: Union[TypeAliasTopLevel, UserDefinedType] self, function_name: str, type_name: Union[TypeAliasTopLevel, UserDefinedType]
) -> None: ) -> None:
for tl_function in self.compilation_unit.functions_top_level: for tl_function in self.compilation_unit.functions_top_level:
if tl_function.name == function_name: # The library function is bound to the first parameter's type
if (
tl_function.name == function_name
and tl_function.parameters
and type_name == tl_function.parameters[0].type
):
self._using_for.using_for[type_name].append(tl_function) self._using_for.using_for[type_name].append(tl_function)
self._propagate_global(type_name) self._propagate_global(type_name)
break break
@ -108,7 +113,12 @@ class UsingForTopLevelSolc(CallerContextExpression): # pylint: disable=too-few-
break break
if c.name == library_name: if c.name == library_name:
for cf in c.functions: for cf in c.functions:
if cf.name == function_name: # The library function is bound to the first parameter's type
if (
cf.name == function_name
and cf.parameters
and type_name == cf.parameters[0].type
):
self._using_for.using_for[type_name].append(cf) self._using_for.using_for[type_name].append(cf)
self._propagate_global(type_name) self._propagate_global(type_name)
found = True found = True

Loading…
Cancel
Save