Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2586 use enum to track variable location instead of string #2682

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

nsiregar
Copy link
Contributor

@nsiregar nsiregar commented Mar 4, 2025

No description provided.

Copy link
Collaborator

@smonicas smonicas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way it's done at the moment the location value wouild still be the string that's for example why you have to use the Enum value in the comparisons. You should make the location the actual Enum when it's set which means going where set_location is called and passing the enum's variant as argument. For example myvar.set_location(VariableLocation("memory")) would set myvar's location to VariableLocation.MEMORY not "memory" the string. After that you would need to check all the places where location is used and if it's used in a comparison (like myvar.location == "memory") you need to change it to compare it against the enum variant (myvar.location == VariableLocation.MEMORY). This for both LocalVariable and StateVariable.

from slither.core.solidity_types.user_defined_type import UserDefinedType
from slither.core.solidity_types.mapping_type import MappingType
from slither.core.solidity_types.elementary_type import ElementaryType
import enum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please import only Enum from enum and not the entire module


if TYPE_CHECKING: # type: ignore
from slither.core.declarations import Function


class VariableLocation(enum.Enum):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing a possible field DEFAULT = "default". I would move this class in variable.py since it's used also by state_variable and seems a better place to have it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants