Skip to content

Commit

Permalink
Merge pull request crytic#730 from snd/snd-dev
Browse files Browse the repository at this point in the history
Ensure MemberAccess.member_type is of type Type
  • Loading branch information
montyly authored Dec 17, 2020
2 parents bb1c1fb + aa3226f commit dcf1797
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
12 changes: 4 additions & 8 deletions slither/core/expressions/member_access.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -26,7 +22,7 @@ def member_name(self) -> str:
return self._member_name

@property
def type(self) -> "Type":
def type(self) -> Type:
return self._type

def __str__(self):
Expand Down
6 changes: 4 additions & 2 deletions slither/solc_parsing/expressions/expression_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions slither/solc_parsing/solidity_types/type_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 != ""]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dcf1797

Please sign in to comment.