From 78caeb691c902cc73f5aa72cf3201e11b3897d15 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Sat, 7 Jan 2023 08:52:16 -0600 Subject: [PATCH] track type aliases at top level --- slither/core/compilation_unit.py | 6 ++++++ slither/solc_parsing/slither_compilation_unit_solc.py | 1 + slither/solc_parsing/solidity_types/type_parsing.py | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/slither/core/compilation_unit.py b/slither/core/compilation_unit.py index d97b7fbf5..2144d4c81 100644 --- a/slither/core/compilation_unit.py +++ b/slither/core/compilation_unit.py @@ -18,6 +18,7 @@ from slither.core.declarations.enum_top_level import EnumTopLevel from slither.core.declarations.function_top_level import FunctionTopLevel from slither.core.declarations.using_for_top_level import UsingForTopLevel from slither.core.declarations.structure_top_level import StructureTopLevel +from slither.core.solidity_types.type_alias import TypeAliasTopLevel from slither.core.scope.scope import FileScope from slither.core.variables.state_variable import StateVariable from slither.core.variables.top_level_variable import TopLevelVariable @@ -46,6 +47,7 @@ class SlitherCompilationUnit(Context): self._pragma_directives: List[Pragma] = [] self._import_directives: List[Import] = [] self._custom_errors: List[CustomError] = [] + self._user_defined_value_types: Dict[str, TypeAliasTopLevel] = {} self._all_functions: Set[Function] = set() self._all_modifiers: Set[Modifier] = set() @@ -215,6 +217,10 @@ class SlitherCompilationUnit(Context): def custom_errors(self) -> List[CustomError]: return self._custom_errors + @property + def user_defined_value_types(self) -> Dict[str, TypeAliasTopLevel]: + return self._user_defined_value_types + # endregion ################################################################################### ################################################################################### diff --git a/slither/solc_parsing/slither_compilation_unit_solc.py b/slither/solc_parsing/slither_compilation_unit_solc.py index 7bae88c5c..201cc48cd 100644 --- a/slither/solc_parsing/slither_compilation_unit_solc.py +++ b/slither/solc_parsing/slither_compilation_unit_solc.py @@ -330,6 +330,7 @@ class SlitherCompilationUnitSolc(CallerContextExpression): user_defined_type = TypeAliasTopLevel(original_type, alias, scope) user_defined_type.set_offset(top_level_data["src"], self._compilation_unit) + self._compilation_unit.user_defined_value_types[alias] = user_defined_type scope.user_defined_types[alias] = user_defined_type else: diff --git a/slither/solc_parsing/solidity_types/type_parsing.py b/slither/solc_parsing/solidity_types/type_parsing.py index b62f908d1..91e320a42 100644 --- a/slither/solc_parsing/solidity_types/type_parsing.py +++ b/slither/solc_parsing/solidity_types/type_parsing.py @@ -243,7 +243,7 @@ def parse_type( sl = caller_context.compilation_unit next_context = caller_context renaming = {} - user_defined_types = {} + user_defined_types = sl.user_defined_value_types else: assert isinstance(caller_context, FunctionSolc) sl = caller_context.underlying_function.compilation_unit