diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index 9e3a12b063..09b5757ec5 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -2,6 +2,7 @@ import re from typing import Dict, TYPE_CHECKING +from slither.core.declarations import Contract from slither.core.declarations.solidity_variables import ( SOLIDITY_VARIABLES_COMPOSED, SolidityVariableComposed, @@ -35,7 +36,9 @@ from slither.core.solidity_types import ( ArrayType, ElementaryType, + UserDefinedType, ) +from slither.core.variables.variable import Variable from slither.solc_parsing.declarations.caller_context import CallerContextExpression from slither.solc_parsing.exceptions import ParsingError, VariableNotFound from slither.solc_parsing.expressions.find_variable import find_variable @@ -112,7 +115,6 @@ def parse_call(expression: Dict, caller_context): # pylint: disable=too-many-st if type_conversion: type_call = parse_type(UnknownType(type_return), caller_context) - if caller_context.is_compact_ast: assert len(expression["arguments"]) == 1 expression_to_parse = expression["arguments"][0] @@ -133,6 +135,8 @@ def parse_call(expression: Dict, caller_context): # pylint: disable=too-many-st expression = parse_expression(expression_to_parse, caller_context) t = TypeConversion(expression, type_call) t.set_offset(src, caller_context.compilation_unit) + if isinstance(type_call, UserDefinedType): + type_call.type.references.append(t.source_mapping) return t call_gas = None diff --git a/slither/solc_parsing/solidity_types/type_parsing.py b/slither/solc_parsing/solidity_types/type_parsing.py index 91e320a425..21ce8e02aa 100644 --- a/slither/solc_parsing/solidity_types/type_parsing.py +++ b/slither/solc_parsing/solidity_types/type_parsing.py @@ -6,7 +6,7 @@ from slither.core.declarations.custom_error_top_level import CustomErrorTopLevel from slither.core.declarations.function_contract import FunctionContract from slither.core.expressions.literal import Literal -from slither.core.solidity_types import TypeAlias +from slither.core.solidity_types import TypeAlias, TypeAliasTopLevel, TypeAliasContract from slither.core.solidity_types.array_type import ArrayType from slither.core.solidity_types.elementary_type import ( ElementaryType, @@ -199,6 +199,9 @@ def _add_type_references(type_found: Type, src: str, sl: "SlitherCompilationUnit if isinstance(type_found, UserDefinedType): type_found.type.add_reference_from_raw_source(src, sl) + elif isinstance(type_found, (TypeAliasTopLevel, TypeAliasContract)): + type_found.type.add_reference_from_raw_source(src, sl) + type_found.add_reference_from_raw_source(src, sl) # TODO: since the add of FileScope, we can probably refactor this function and makes it a lot simpler @@ -362,6 +365,7 @@ def parse_type( if name in renaming: name = renaming[name] if name in user_defined_types: + _add_type_references(user_defined_types[name], t["src"], sl) return user_defined_types[name] type_found = _find_from_type_name( name, @@ -382,6 +386,7 @@ def parse_type( if name in renaming: name = renaming[name] if name in user_defined_types: + _add_type_references(user_defined_types[name], t["src"], sl) return user_defined_types[name] type_found = _find_from_type_name( name,