Merge pull request #730 from snd/snd-dev

Ensure MemberAccess.member_type is of type Type
pull/733/head
Feist Josselin 4 years ago committed by GitHub
commit dcf1797dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      slither/core/expressions/member_access.py
  2. 6
      slither/solc_parsing/expressions/expression_parsing.py
  3. 7
      slither/solc_parsing/solidity_types/type_parsing.py

@ -1,19 +1,15 @@
from typing import TYPE_CHECKING
from slither.core.expressions.expression import Expression
from slither.core.expressions.expression_typed import ExpressionTyped
if TYPE_CHECKING:
from slither.core.solidity_types.type import Type
from slither.core.solidity_types.type import Type
class MemberAccess(ExpressionTyped):
def __init__(self, member_name, member_type, expression):
# assert isinstance(member_type, Type)
# TODO member_type is not always a Type
assert isinstance(member_type, Type)
assert isinstance(expression, Expression)
super().__init__()
self._type: "Type" = member_type
self._type: Type = member_type
self._member_name: str = member_name
self._expression: Expression = expression
@ -26,7 +22,7 @@ class MemberAccess(ExpressionTyped):
return self._member_name
@property
def type(self) -> "Type":
def type(self) -> Type:
return self._type
def __str__(self):

@ -802,11 +802,13 @@ def parse_expression(expression: Dict, caller_context: CallerContext) -> "Expres
if name == "MemberAccess":
if caller_context.is_compact_ast:
member_name = expression["memberName"]
member_type = expression["typeDescriptions"]["typeString"]
member_type = parse_type(
UnknownType(expression["typeDescriptions"]["typeString"]), caller_context
)
member_expression = parse_expression(expression["expression"], caller_context)
else:
member_name = expression["attributes"]["member_name"]
member_type = expression["attributes"]["type"]
member_type = parse_type(UnknownType(expression["attributes"]["type"]), caller_context)
children = expression["children"]
assert len(children) == 1
member_expression = parse_expression(children[0], caller_context)

@ -70,6 +70,8 @@ def _find_from_type_name( # pylint: disable=too-many-locals,too-many-branches,t
enum_name = name
if enum_name.startswith("enum "):
enum_name = enum_name[len("enum ") :]
elif enum_name.startswith("type(enum"):
enum_name = enum_name[len("type(enum ") : -1]
# all_enums = [c.enums for c in contracts]
# all_enums = [item for sublist in all_enums for item in sublist]
# all_enums += contract.slither.enums_top_level
@ -103,7 +105,8 @@ def _find_from_type_name( # pylint: disable=too-many-locals,too-many-branches,t
if not var_type:
if name.startswith("function "):
found = re.findall(
"function \(([ ()a-zA-Z0-9\.,]*?)\)(?: returns \(([a-zA-Z0-9() \.,]*)\))?", name
"function \(([ ()\[\]a-zA-Z0-9\.,]*?)\)(?: payable)?(?: (?:external|internal|pure|view))?(?: returns \(([a-zA-Z0-9() \.,]*)\))?",
name,
)
assert len(found) == 1
params = [v for v in found[0][0].split(",") if v != ""]
@ -149,7 +152,7 @@ def _find_from_type_name( # pylint: disable=too-many-locals,too-many-branches,t
if name.startswith("mapping("):
# nested mapping declared with var
if name.count("mapping(") == 1:
found = re.findall("mapping\(([a-zA-Z0-9\.]*) => ([a-zA-Z0-9\.\[\]]*)\)", name)
found = re.findall("mapping\(([a-zA-Z0-9\.]*) => ([ a-zA-Z0-9\.\[\]]*)\)", name)
else:
found = re.findall(
"mapping\(([a-zA-Z0-9\.]*) => (mapping\([=> a-zA-Z0-9\.\[\]]*\))\)", name,

Loading…
Cancel
Save